尝试在案例中排序“排序依据”时出现未知错误

时间:2016-02-11 05:47:35

标签: mysql

 SELECT 
     *,
     a.FK_psPatRegisters,
     CASE
         WHEN (SELECT count(x.FK_psPatRegisters) FROM trxpost x WHERE x.FK_psPatRegisters = a.FK_psPatRegisters AND a.FK_psPatRegisters 
             NOT IN (SELECT FK_psPatRegisters FROM bizboxgntr)) > 1 THEN 1
         WHEN (SELECT count(xxx.FK_psPatRegisters) FROM bizboxgntr xxx WHERE xxx.FK_psPatRegisters = a.FK_psPatRegisters) AND 
              (SELECT distinct (SELECT sum(aa.amount) FROM bizboxgntr aa WHERE aa.FK_employee = xxy.FK_employee AND year(aa.datetime) = year(xxy.datetime)) 
              FROM bizboxgntr xxy WHERE xxy.FK_psPatregisters = a.FK_psPatRegisters) < 20000 THEN 2 
         WHEN (SELECT distinct (SELECT sum(ab.amount) FROM bizboxgntr ab WHERE ab.FK_employee = xxz.FK_employee AND year(ab.datetime) = year(xxz.datetime)) 
              FROM bizboxgntr xxz WHERE xxz.FK_psPatregisters = a.FK_psPatRegisters) = 20000 THEN 4
         WHEN (SELECT distinct (SELECT sum(ac.amount) FROM bizboxgntr ac WHERE ac.FK_employee = xxa.FK_employee AND year(ac.datetime) = year(xxa.datetime)) 
              FROM bizboxgntr xxa WHERE xxa.FK_psPatregisters = a.FK_psPatRegisters) > 20000 THEN 5
         ELSE 3 
     END AS `post`
FROM bizboxtbl a
ORDER BY post
  

ORDER BY

     

返回错误“子查询返回超过1行”,但如果我删除ORDER BY或按其他列排序查询运行没有错误

     

SCREENSHOTS:
  With Order By
  Without Order By

0 个答案:

没有答案