首页 > 代码库 > sql面试题-----行转列

sql面试题-----行转列

   tem数据表如下图

技术分享

 1 select Time as 日期,
 2 sum 
 3 (
 4          case 
 5      when Shengfu=  then 1
 6        else  0
 7       end
 8 ) as 胜,
 9 sum
10 ( 
11        case
12      when Shengfu= then 1
13         else 0
14      end 
15 )  as16 
17  from tem
18    group by Time

执行结果如下图:

技术分享

 

sql面试题-----行转列