SQL查询统计
表名:DRI表中的字段: DRI_ID,NAME(姓名),INCOME(津贴)
DRI_ID NAME INCOME
1 A 200
2 A 150
3 A 350
4 B 250
5 B 400
6 C 600
最后的结果应该是:
NAME INCOME
A 700
B 650
C 600
请问用SQL语句怎样写啊,小弟我急需啊,先谢过了 --------------------编程问答-------------------- select name,Count(Income) from dri group by name --------------------编程问答--------------------
select [name],sum([income]) from dri group by name
是不是这样?
靠,好久没写Sql,不确定哦 --------------------编程问答-------------------- 不好意思,用过函数了
赫赫
select name,Sum(Income) from dri group by name --------------------编程问答-------------------- 津贴的结果是降序排列的 --------------------编程问答--------------------
select [name],sum(income) as income from test group by [name] order by income desc--------------------编程问答-------------------- 在问,怎样在输出的名字前加上排名序号呢?
例如:
排名 NAME INCOME
1 A 700
2 B 650
3 C 600
--------------------编程问答--------------------
select rank() over (order by t.income desc ) [No],*--------------------编程问答-------------------- 请问楼上的 t是什么意思啊? --------------------编程问答-------------------- select name,sum(income)as income from DRI group by name order by name desc --------------------编程问答-------------------- t 就是select [name],sum(income) as income from dri group by [name] 查出来记录构成的表的别名 --------------------编程问答-------------------- 请问楼上的 t是什么意思啊?
from
(select
[name],sum(income) as income from dri group by [name]) t
-----------------------
把select [name],sum(income) as income from dri group by [name] 查询的结果作为一张表,表的别名为t;
--------------------编程问答-------------------- select [name],sum([income]) from dri group by name order by [income] ,[name] desc
补充:.NET技术 , C#