最近在复习过程中愈发觉得,有些东西久了不用,真的会忘~——~。
将上面的表格转换为下面的表格
我拼sql拼了好久还是没弄出来,还是偶然看到我以前的笔记,才想起有行转列这样的操作(太久没有写过复杂点的sql了)
1 SELECT YEAR 2 , 3 max( CASE MONTH WHEN '1' THEN amount ELSE 0 END ) m1, 4 max( CASE MONTH WHEN '2' THEN amount ELSE 0 END ) m2, 5 max( CASE MONTH WHEN '3' THEN amount ELSE 0 END ) m3, 6 max( CASE MONTH WHEN '4' THEN amount ELSE 0 END ) m4 7 FROM 8 test_offer GROUP BY year;
要多复习呀,骚年!!!