仿 oracle 的decode效果查询_MySQL

WBOY
發布: 2016-06-01 13:51:43
原創
942 人瀏覽過

今天遇到群里发的一个问题,觉得有点意思,发上来看一下

仿 oracle 的decode效果查询_MySQL

以下代码在MYSQL中测试通过,MSSQL应该能跑通,未测试。

#创建表如下<br>create temporary table tmp (a int, b int ,c int);<br>insert into tmp VALUES (1,10,1),(10,10,2),(10,100,2);<br>#mysql执行<br>select sum(case when c = '1' then A else B end) from tmp<br>#oracle执行<br>select sum(decode(c,'1',a,b)) from tmp<br>#普通联合查询<br>select sum(d) from <br>(<br>select a as d from tmp where c=1<br> union <br>select b as d  from tmp where c=2<br>)
登入後複製
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!