如何编写以下sql语句
select * from blogimage where blog_id = '1' and orientation = 'h' 但是..。我想加一句...
IF(and only if) orientation = 'h' is null... then use orientation = 'v'发布于 2014-02-15 12:33:27
如果您只想获取1条使用偏好方向的记录= 'h‘
SELECT * FROM blogimage
WHERE blog_id = '1' AND (orientation = 'h' OR orientation = 'v')
ORDER BY orientation ASC LIMIT 1发布于 2014-02-15 12:44:45
此语句具有有效的Case语句。但是,如果需要if exists语句,我认为需要使用存储过程。这就是你想要创造的吗?
使用此语句,您将返回一行。如果有一个h行,你会得到它。如果不存在,您将返回一个v行,除非它也不存在。
select * from blogimage where blog_id = '1' and (orientation = 'h' Or orientation = 'v') Order By Case When orientation = 'h' Then 0 Else 1 End Asc Limit 1https://stackoverflow.com/questions/21793388
复制相似问题