首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问一个SQL语句(,马上就结)

2012-02-03 
请教一个SQL语句(在线等,马上就结)表结构如下idpidN1N21110201210101310101.........2155225523552.......

请教一个SQL语句(在线等,马上就结)
表结构如下
id       pid     N1       N2
1           1         10       20
1           2         10       10
1           3         10       10
1           ...     ...     ...
2           1         5         5
2           2         5         5
2           3         5         5
2           ...     ...     ...  
现在想得到如下查询结果,查询条件是查询pid从1到3
id         N1       N2
1           30       40
2           15       15
这个语句该怎么写


[解决办法]
select id,sum(N1) as N1,sum(N2) as N2
from 表
where pid between 1 and 3
group by id
[解决办法]
select pid,sum(N1) as N1,sum(N2) as N2 from table1 group by pid
[解决办法]
--TRY
SELECT id,sum(N1),SUM(N2) FROM tablename where pid in ( '1 ', '2 ', '3 ') group by id

热点排行