文章詳情頁(yè)
MYSQL 運(yùn)算的問(wèn)題
瀏覽:127日期:2022-06-18 17:02:48
問(wèn)題描述
我的某個(gè)MYSQL數(shù)據(jù)表A中有兩個(gè)字段分別是 type 和 param。我需要當(dāng)type的值為1的時(shí)候從表B中取一個(gè)值,當(dāng)type的值為2的時(shí)候從表C中取一個(gè)值。
要用一條語(yǔ)句來(lái)實(shí)現(xiàn)要怎么寫(xiě)(其實(shí)主要是在SELECT和FROM之間做一個(gè)type值的判斷)
問(wèn)題解答
回答1:方法一:
select case when a.type=1 then b.col else c.col endfrom a,b,c
方法二:
select a.type, b.colfrom a, bwhere a.type=1unionselect a.type, c.colfrom a, cwhere a.type=2回答2:
select case when type = 1 then a.*** else b.*** end as *** from a,b,c ...
上一條:php mysql數(shù)據(jù)庫(kù) 產(chǎn)品分類(lèi)與產(chǎn)品詳情應(yīng)該怎么做?下一條:mysql5.7中g(shù)roup by和mysql5.5中g(shù)roup by的結(jié)果不一樣
相關(guān)文章:
1. 關(guān)于docker下的nginx壓力測(cè)試2. css3 - 這個(gè)右下角折角用css怎么畫(huà)出來(lái)?3. debian - docker依賴(lài)的aufs-tools源碼哪里可以找到啊?4. javascript - 一個(gè)關(guān)于客戶(hù)端和前端通信的疑惑?5. javascript - webpack熱加載配置不生效6. java - 根據(jù)月份查詢(xún)多個(gè)表里的內(nèi)容怎么實(shí)現(xiàn)好?7. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。8. css3 - 沒(méi)明白盒子的height隨width的變化這段css是怎樣實(shí)現(xiàn)的?9. python3.x - c++調(diào)用python310. android - 課程表點(diǎn)擊后浮動(dòng)后邊透明可以左右滑動(dòng)的界面是什么?
排行榜

熱門(mén)標(biāo)簽