我的(简化)查询
SELECT name, city FROM some.tbl WHERE name LIKE "%clarendon%" ORDER BY city, name
我得到类似下面的内容:
name city Budget Lodge Clarendon Clarendon Clarendon Artillery Lane London Clarendon Barbican Studios London Clarendon Brushfield St London Clarendon Canary Central London Clarendon Commercial St London Clarendon Cottages Sassafras Clarendon Discovery Dock East London Clarendon Gooch House London Clarendon House And Gardens Kew Clarendon Luxury Apartments Edinburgh Clarendon Manning Place Richmond Clarendon Minories London Clarendon Motel North Conway Clarendon Pepys St London Clarendon Puma Court London Clarendon Steward St London Clarendon Vine St London Clarendon Wellington St London Clarendon Wraysbury Staines Hotel Clarendon Quebec The Clarendon London The Clarendon Bantry Bay Cape Town The Clarendon Fresnaye Cape Town The Clarendon Hotel Newcastle
我想得到的是这个 -
col.name保持其顺序,但col.city按col.name片段排序,并使用单词clarendon:
name city Budget Lodge Clarendon Clarendon Clarendon Luxury Apartments Edinburgh Clarendon House And Gardens Kew Clarendon Artillery Lane London Clarendon Barbican Studios London Clarendon Brushfield St London Clarendon Canary Central London Clarendon Commercial St London Clarendon Discovery Dock East London Clarendon Gooch House London Clarendon Minories London Clarendon Pepys St London Clarendon Puma Court London Clarendon Steward St London Clarendon Vine St London Clarendon Wellington St London Clarendon Motel North Conway Clarendon Manning Place Richmond Clarendon Cottages Sassafras Clarendon Wraysbury Staines Hotel Clarendon Quebec The Clarendon Bantry Bay Cape Town The Clarendon Fresnaye Cape Town The Clarendon London The Clarendon Hotel Newcastle
修改 错字 - 当然是“按名称排序,城市” 但问题仍然存在,
答案 0 :(得分:1)
问题不正确。您发布的查询已经为您提供了第二个结果。
[编辑]
ORDER BY
substr(name, 1, 9), city, name
答案 1 :(得分:0)
您的第一个结果似乎是使用ORDER BY name, city
而不是(如您所声称的)ORDER BY city, name
。
第二个结果可以通过以下方式返回:
SELECT name, city
FROM some.tbl
WHERE name LIKE "%clarendon%"
ORDER BY SUBSTRING_INDEX(name, 'Clarendon', 1)
, city
, name ;
答案 2 :(得分:-1)
此查询简单查询可满足您的需求:
SELECT name, city
FROM some.tbl
WHERE name LIKE "%clarendon%"
ORDER BY name ASC, city ASC