1.MySql中IF表达式的用法
IF(expr1,expr2,expr3)
eg: select *,if(sva=1,"男","女") as ssva from taname where sva != ""
如果 expr1 是TRUE (expr1 <> 0 and expr1 <> NULL),则 IF()的返回值为expr2; 否则返回值则为 expr3。IF() 的返回值为数字值或字符串值,具体情况视其所在语境而定。
2. Mysql中排序中使用case when
SELECT FirstName, LastName
FROM Person.Contact
ORDER BY CASE LastName
WHEN 'Wright' THEN '0'
WHEN 'Jenkins' THEN '1'
WHEN 'Torres' THEN '2'
WHEN 'Sanchez' THEN '3'
ELSE LastName
END
按照名字排序