当前位置:Gxlcms > 数据库问题 > sql语句if,case when

sql语句if,case when

时间:2021-07-01 10:21:17 帮助过:24人阅读

if(direction=0,看涨,看跌) directionName FROM t_order_detail detail LEFT JOIN t_order o ON o.id = detail.orderId LEFT JOIN t_catagory catagory ON catagory.id = o.catId LEFT JOIN t_user u ON u.id = o.userId

2.case when

case 列名

when 条件 then 结果

else 其它结果

end 别名

例:

SELECT 
CASE detail.`status` WHEN 0 THEN 未开仓
WHEN 1 THEN 已开仓
WHEN 2 THEN 已平仓
ELSE 取消订单 END
status,
CASE o.type WHEN 0 THEN 单期
WHEN 1 THEN 多期
ELSE 策略 END 
typeName
FROM t_order_detail detail
LEFT JOIN t_order o ON o.id = detail.orderId

 

sql语句if,case when

标签:span   expr   pen   account   sel   bsp   blog   mount   nbsp   

人气教程排行