sql语句操作之查询操作1

请用sql语句将下列表格:

 变为表格2

 

 sql语句如下:

select year,
  round(max(if(mounth=1,amount,0)),2) m1,            # 将值赋给m1
  round(max(if(mounth=2,amount,0)),2) m2
from jj
group by year;

#  sql语句中的if(mounth=1,amount,0)表示如果mounth=1则取amount值否则取0

猜你喜欢

转载自blog.csdn.net/qq_16069927/article/details/81186721