Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

aggregate function

Former Member
0 Likes
647

Hi,

May I know aggregate function sum, count, max, min, average in select statement need to have group by?

I know sum need to have, what about others?

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
591

Hi

If you are using aggregate functions, then its necessary for you to use <b>group by</b> clause.

Eg:

SELECT d.depid, d.name, COUNT(*) AS EMPLOYEE_COUNT

FROM department d JOIN employee e

ON

d.DEPID = e.DEPID

GROUP BY d.depid, d.name

Regards

Raj

4 REPLIES 4
Read only

Former Member
0 Likes
592

Hi

If you are using aggregate functions, then its necessary for you to use <b>group by</b> clause.

Eg:

SELECT d.depid, d.name, COUNT(*) AS EMPLOYEE_COUNT

FROM department d JOIN employee e

ON

d.DEPID = e.DEPID

GROUP BY d.depid, d.name

Regards

Raj

Read only

Former Member
0 Likes
591

if you are using aggregate fn and other fields also in select statement then you have to use groupby for other fields.

suppose

select mblnr sum( menge ) into table itab from mseg where bwart = '101' group by mblnr.

since mblnr is not in aggregate fn so you have to use mblnr in group by clause (it may be any no of fields without aggregate fn) if you are using simply aggregate fn then no need of group by

select sum( menge ) into table itab from mseg where bwart = '101' .

regards

shiba dutta

Read only

0 Likes
591

Hi,

I know if having other fields as well then other field need to have group by/order by for sum.

Can let me know if the rest like count, max, min, average also need to have group by /order by

thanks

points given.

Read only

Former Member
0 Likes
591

if u r using more dan one field in da select clause den u hav to specify teh grp by caluse otherwise nt..