E
E
evgenyt20002019-04-28 17:41:15
Oracle
evgenyt2000, 2019-04-28 17:41:15

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

3 answer(s)
E
evgenyt2000, 2019-04-28
@evgenyt2000

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;

R
Rsa97, 2019-04-28
@Rsa97

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.

K
Konstantin Tsvetkov, 2019-04-28
@tsklab

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 question

Ask a Question

731 491 924 answers to any question