Answer the question
In order to leave comments, you need to log in
Why doesn't ORACLE SQL count aggregate functions?
Can't do grouping
SELECT MONTH(LESSONDATETIME),YEAR(LESSONDATETIME),COUNT(*)
FROM LESSON
WHERE YEAR(LESSONDATETIME) AND CLASSID=102
GROUP BY MONTH (LESSONDATETIME)
ORDER BY 1
Answer the question
In order to leave comments, you need to log in
Thanks all figured out
select
to_char(LESSONDATETIME,'MM'),to_char(LESSONDATETIME,'YYYY'),count(LESSONDATETIME)
FROM LESSON
WHERE to_char(LESSONDATETIME,'YYYY')=2017
having
count(LESSONDATETIME) > 0
group by
to_char( LESSONDATETIME,'MM'),to_char(LESSONDATETIME,'YYYY')
order by
to_char(LESSONDATETIME,'MM') asc;
According to the SQL standard, when grouping, all selectable fields must be aggregate functions or fields on which the grouping is performed.
YEAR(LESSONDATETIME) doesn't match either of these conditions.
WHERE YEAR(LESSONDATETIME)
what is equal? Therefore, you need to take each condition in brackets.
SELECT YEAR(LESSONDATETIME), MONTH(LESSONDATETIME), COUNT(*)
FROM LESSON
WHERE (CLASSID = 102)
GROUP BY YEAR(LESSONDATETIME), MONTH(LESSONDATETIME)
HAVING YEAR(LESSONDATETIME) = 2017
ORDER BY 1, 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question