sql server 點滴累計,sqlserver

來源:互聯網
上載者:User

sql server 點滴累計,sqlserver
1.挑選清單中的列無效,因為該列沒有包含在彙總函式或 GROUP BY 子句中

答:即指定 GROUP BY 時,挑選清單中任一非彙總運算式內的所有列都應包含在 GROUP BY 列表中,或者 GROUP BY運算式必須與挑選清單運算式完全符合。

2. case when then else end 文法的使用

select
i.index_name,i.index_def,
  sum(case when w.years= 2014 then w.actual_value else 0 end) as a1,
  sum(case when w.years= 2014 then w.ranking else 0 end ) as r1,

  sum(case when w.years= (2014-1) then w.actual_value else 0 end ) as a2,
  sum(case when w.years= (2014-1) then w.ranking else 0 end ) as r2,


from bm_work w,bm_index i
where
w.indexdef_id=i.uuid and
w.ent_id='2c90e4da49514c750149515eb56f0003' and w.summary_state=2
group by i.index_name,i.index_def;

這個語句達到這樣一個效果



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.