MYSQL 运算的问题

我的某个MYSQL数据表A中有两个字段分别是 type 和 param。我需要当type的值为1的时候从表B中取一个值,当type的值为2的时候从表C中取一个值。

要用一条语句来实现要怎么写(其实主要是在SELECT和FROM之间做一个type值的判断)

阅读 1.8k
2 个回答

方法一:

select case when a.type=1 then b.col else c.col end
from a,b,c

方法二:

select a.type, b.col
from a, b
where a.type=1
union
select a.type, c.col
from a, c
where a.type=2
select case when type = 1 then a.*** else b.*** end as *** from a,b,c ...
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题