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

搜狐畅游的一道SQL笔试题

表名为table的表内容如下
Year month value
2009  1    1.1
2009  2    1.2
2009  3    1.3
2009  4    1.4
2010  1    2.1
2010  2    2.2
2010  3    2.3
2010  4    2.4


要求查询结果为

year  m1  m2  m3  m4
2009  1.1  1.2  1.3  1.4
2010  2.1  2.2  2.3  2.4



SQL code:
select year,sum(case when month=1 then value) as m1
,sum(case when month=2 then value) as m2
,sum(case when month=3 then value) as m3
,sum(case when month=4 then value) as m4
from tb
group by year


select year,[m1]=max(case when year=[year] and month='1' then value end),
[m2]=max(case when year=[year] and month='2' then value end),
[m3]=max(case when year=[year] and month='3' then value end),
[m4]=max(case when year=[year] and month='4' then value end)
from tb
group by year



SQL code:

declare @table table ([Year] int,[month] int,[value] numeric(2,1))
in


相关问答:

sql server 存储过程循环赋值的问题

小弟是个新手 现在有个问题一直不能解决
例如
procedure produce_proc
    @p001 nvarchar(8000),
    @p002 nvarchar(8000),
    @p003 nvarchar(8000),
  & ......

关于group by的sql语句?

  with adod_dict do
    begin
    close;
    commandtext:='select bgqxcode,count(*) wjsl from wscl_wsda_file where wjnd=:tnd group by bgqxcode'; ......

sql 问题

DateTime startTime=DateTime(em_1.Text)
DateTime endTime=DateTime(em_2.Text)

string sql
sql = dw_1.GetSQLSelect()+"Where (StartTime> '"+startTime+"') and (EndTime ......

oracle sql developer 查询显示中文乱码

环境:1.win2003server+oracle9i
2.oracle9i字符集为AMERICAN_AMERICA.WE8ISO8859P1
3.oracle sql developer版本 1.5.5
现象描述: 1.在sql developer 中查询oracle中的某个表,中文全部显示为乱码。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号