How to use group by in SQL Server query?

前端 未结 5 1296
死守一世寂寞
死守一世寂寞 2020-12-10 16:37

I have problem with group by in SQL Server

I have this simple SQL statement:

select * 
from Factors 
group by moshtari_ID

and I get

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 16:51

    You need to apply aggregate function such as max(), avg() , count() in group by.

    For example this query will sum totalAmount for all moshtari_ID

    select moshtari_ID,sum (totalAmount) from Factors group by moshtari_ID;
    

    output will be

    moshtari_ID    SUM
    2              120000 
    1              200000
    

提交回复
热议问题