sql备忘

第一个代码是对的,第二个是错的,*和自定义表达式的顺序前后调换

SELECT *,salary*12*(1+IFNULL(commission_pct,0)) AS 年薪
FROM `employees`
ORDER BY salary*12*(1+IFNULL(commission_pct,0)) DESC;
SELECT salary*12*(1+IFNULL(commission_pct,0)) AS 年薪,*
FROM `employees`
ORDER BY salary*12*(1+IFNULL(commission_pct,0)) DESC;

这样以别名排序也是对的

SELECT *,salary*12*(1+IFNULL(commission_pct,0)) AS 年薪
FROM `employees`
ORDER BY `年薪` DESC;
发布了186 篇原创文章 · 获赞 21 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/sinat_23971513/article/details/105150010