~会飞的鱼

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1、行转列问题

1 select year,sum(case when month<=3 then sale else 0 end) as '第一季度',
2 sum(case when (month>3 and month<=6) then sale else 0 end) as '第二季度',
3 sum(case when (month>6 and month<=9) then sale else 0 end) as '第三季度',
4 sum(case when (month>9 and month<=12) then sale else 0 end) as '第四季度'
5 from sales group by Year;

 2、有A(id,sex,par,c1,c2),B(id,age,c1,c2)两张表,其中A.id与B.id关联,现在要求写一条SQL语句,将B中age>50的记录的c1、c2更新到A表中统一记录中的c1、c2字段中。

答案:

1 update a inner join b on a.id=b.id and b.age>50 set a.c1=b.c1,a.c2=b.c2;

 

posted on 2013-09-04 21:52  ~会飞的鱼  阅读(172)  评论(0编辑  收藏  举报