SQL Query: Need order by count, most must be on top, the rest follows

前端 未结 3 1377
孤街浪徒
孤街浪徒 2021-02-09 20:14

TABLEA

JobCode Job1 Job2 Job3 zip
------- ---- ---- ---- ----------
F       F    S    NULL 90030
F       F    S    NULL 90031
F       F    S    NULL 90031
F              


        
3条回答
  •  梦谈多话
    2021-02-09 20:36

    SELECT 
      JobCode, Job1, Job2, Job3, order_jobs.zip
    FROM
      jobs
      JOIN (SELECT zip, COUNT(*) AS zipcount FROM jobs GROUP BY zip) ordering 
    ON jobs.zip = ordering.zip
    ORDER BY zipcount DESC
    

提交回复
热议问题