我如何IF...THEN在SQL SELECT声明中执行?
例如:
SELECT IF(Obsolete = 'N' OR InStock = 'Y' ? 1 : 0) AS Saleable, * FROM Product
Run Code Online (Sandbox Code Playgroud) 我希望首先获得特定位置的所有配置文件:
SELECT * FROM profile
WHERE location IN ('a', 'b', 'c') OR isDefault=1
ORDER BY location IN ('a', 'b') DESC, -- put to the front if location in 'a','b'
isDefault DESC, -- for each of both groups, put default profiles before the others.
location ASC -- and sort each of the up to four groups by location.
Run Code Online (Sandbox Code Playgroud)
这会引发错误:"关键字'IN'附近的语法不正确." 如果我删除了order子句,则返回结果.
这有什么不对?