易截截图软件、单文件、免安装、纯绿色、仅160KB

sql语句求助

年份 | 季度 | 数量
1999 | 1    | 1200
1999 | 2    | 1100
1999 | 3    | 1300
1999 | 4    | 1000
2000 | 1    | 1400
2000 | 2    | 900
2000 | 3    | 1250
2000 | 4    | 1000
由这张表查询出如下表:
年份 | 第一季度 | 第二季度 | 第三季度 | 第四季度
1999 | 1200    | 1100    | 1300    | 1000
2000 | 1400    | 900      | 1250    | 1000


select year,
case when season = 1 then sum(count) end,
case when season = 2 then sum(count) end,
case when season = 3 then sum(count) end,
case when season = 4 then sum(count) end
from t group by year;

引用
select year,
case when season = 1 then sum(count) end,
case when season = 2 then sum(count) end,
case when season = 3 then sum(count) end,
case when season = 4 then sum(count) end
from t group by year;

真快啊

可能不对,修改下:

select year,
sum(case when season = 1 then count end),
sum(case when season = 2 then count end),
sum(case when season = 3 then count end),
sum(case when season = 4 then count end)
from t group by year;

引用


真快啊
<


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

Sql排序 - MS-SQL Server / 基础类

我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 ......

sql 截取字符串

我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......

sql 存储过程

我要做一个定点事件,是每天晚上12点就把三个表里的信息放入一个表里,我想用存储过程来写,怎么写呢?,那位高手帮帮忙吧,非常感谢!

用户名是唯一的
表A  字段
用户名:Name  ,邮箱:Ema ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号