Naive Bayes algorithm implemented using SQL only