例如: 有一张表employees, 这张表至少有last_name(姓名)_,salary(薪水),commission_pct(一个计算年薪的字段) department_id (部门id)这几个字段.
现在想要查询: 根据年薪升序,名字的首字母降序,查询出last_name,年薪, department_id.
如果按照如下,order_by后面的年薪家了'',就是错误的.
SELECT last_name, salary * 12 * ( 1+ IFNULL( commission_pct, 0 )) AS '年薪', department_id FROM employees ORDER BY '年薪 'ASC, last_name DESC;
正确的是将order by后面的年薪的引号去掉.如下:
SELECT last_name, salary * 12 * ( 1+ IFNULL( commission_pct, 0 )) AS '年薪', department_id FROM employees ORDER BY 年薪 ASC, last_name DESC;