sql - Selected columns that are not in group by -
i quetions sql. example have table
name surname price adress john smith 100 adress123 alex martin 200 adress2 john smith 300 adress123
and want group records name same.and records prices must sum()
write query this
select sum(price),name total_price table1 group a.name
but when want select other columns should group
... group a.name,a.surname,a.adress
i want select columns without group by. want ask best way selecting other columsn without using group condition?
i waiting result
200 alex martin adress2 210 john smith adress123
but don't want group surname , adress column
you can arbitrary value rest of columns using min()
or max()
:
select sum(price) total_price, name, max(surname) surname, max(address) address table1 group a.name;
Comments
Post a Comment