表TAB1有以下数据
ID Name num weight
1001 小五 10 100
1005 小五 20 200
1002 小李 10 12
1003 小五 10 12
1004 NULL或( )10 12
1006 小张 7 20ID为唯一值 我要统计结果如下、
name num weight count
小五 40 312 3
小李 10 12 1
小张 7 20 1
空(NULL) 10 12 1请问如何这条语句的汇总语句
ID Name num weight
1001 小五 10 100
1005 小五 20 200
1002 小李 10 12
1003 小五 10 12
1004 NULL或( )10 12
1006 小张 7 20ID为唯一值 我要统计结果如下、
name num weight count
小五 40 312 3
小李 10 12 1
小张 7 20 1
空(NULL) 10 12 1请问如何这条语句的汇总语句
Name,
SUM(num) AS num,
SUM(weight) AS weight,
COUNT(*) AS [count]
FROM tb1
GROUP BY Name
select name,sum(num) num,sum( weight) weight,count(name)
from A
group by name
drop table TAB1
gocreate table TAB1(ID int,Name char(10),num int,weight int)
insert into TAB1
select 1001,'小五',10,100
union all
select 1005,'小五',20,200
union all
select 1002,'小李',10,12
union all
select 1003,'小五',10,12
union all
select 1004,'',10,12
union all
select 1006,'小张',7,20select name,sum(num) num,sum(weight) weight,count(name) count
from TAB1
group by name
order by count desc,name descname num weight count
---------- ----------- ----------- -----------
小五 40 312 3
小张 7 20 1
小李 10 12 1
10 12 1(所影响的行数为 4 行)
SUM(num) AS num,
SUM(weight) AS weight,
COUNT(*) AS cou FROM tab1
GROUP BY Name
from TAB1
group by name