您的位置:首頁技術文章
文章詳情頁

MYSQL 運算的問題

瀏覽:103日期:2022-06-18 17:02:48

問題描述

我的某個MYSQL數據表A中有兩個字段分別是 type 和 param。我需要當type的值為1的時候從表B中取一個值,當type的值為2的時候從表C中取一個值。

要用一條語句來實現要怎么寫(其實主要是在SELECT和FROM之間做一個type值的判斷)

問題解答

回答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 ...

相關文章:
国产综合久久一区二区三区