MySQL按SubQuery排序

时间:2015-10-28 14:59:44

标签: mysql group-by subquery sql-order-by

我正在尝试提供排名最多的客户列表。我似乎无法弄清楚如何保持子查询排序的列表。这是我的疑问:

SELECT
  c.*,
  state.abbreviation AS state,
  country.abbreviation AS country
FROM main_customers AS c
  LEFT JOIN dict_stateProvince AS state ON c.state = state.id
  LEFT JOIN dict_country AS country ON c.country = country.id
WHERE c.id IN (SELECT customerId
               FROM main_orders
               GROUP BY customerId
               ORDER BY COUNT(*) DESC)
LIMIT 50;

如何使主查询的顺序与子查询保持一致?

1 个答案:

答案 0 :(得分:1)

您的子查询没有真正的顺序,因为html = "<br><br><br>Hello<br>Check"; Regex.Replace(s,"^(?:<br>)+","\r\n") //Returns Hello<br>Check 忽略了排序。但目的很明确。因此,请使用IN

join