简体   繁体   中英

SQL SELECT, GROUP BY

Why do I have to group all my selected columns in group by if i started to group by one column?

For instance, why can't i just have only two groups? as below:

SELECT A, B, C, D
FROM MYTB
GROUB BY A, B

You can group by as many elements as you want. Just make sure any non-grouped elements in your select have some aggregation.

SELECT A, B, SUM(C), MAX(D)
FROM MYTB
GROUP BY A, B

See

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM