如何按此声明排序?

时间:2016-03-31 08:48:04

标签: mysql sql-order-by

这是代码及其工作原理。但我不知道如何通过全名来订购。

请检查:http://sqlfiddle.com/#!9/269a2/2

 UPDATE myTable
JOIN (
  SELECT m1.id, COUNT(m2.id)+1 ord FROM myTable m1
  LEFT JOIN myTable m2 ON m1.id > m2.id AND m1.company = m2.company 
  GROUP BY m1.id
) z1 ON myTable.id = z1.id
JOIN (
  SELECT 1 ord, '0000-1112' assign_num UNION ALL
  SELECT 2 ord, '0000-1501' assign_num UNION ALL
  SELECT 3 ord, '0000-1120' assign_num
) z2
  ON z1.ord = z2.ord
SET myTable.assign_num = z2.assign_num
WHERE myTable.company = 'company1'

0 个答案:

没有答案