扫码关注官方订阅号
我的某个MYSQL数据表A中有两个字段分别是 type 和 param。我需要当type的值为1的时候从表B中取一个值,当type的值为2的时候从表C中取一个值。
要用一条语句来实现要怎么写(其实主要是在SELECT和FROM之间做一个type值的判断)
光阴似箭催人老,日月如移越少年。
方法一:
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 ...
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
方法一:
方法二: