我们有一个包含名称和值的表,例如:["Tom","500"] ["Amy","300"] ["Sam","300"] ["Mike","100"]
http://sqlfiddle.com/#!9/94d33b/1
[如何进行查询以搜索“ Amy”并在顶部列出“ Amy”,以及所有值按降序等于或低于“ Amy”的记录:["Amy","300"] ["Sam","300"] ["Mike","100"]
相同的搜索“ Sam”的查询应在顶部显示“ Sam”],显示具有same value的“ Amy”为“ Sam”,然后在它们下面的每个人:["Sam","300"]["Amy","300"] ["Mike","100"]
我们有一个带有名称和值的表,例如:[“ Tom”,“ 500”] [“ Amy”,“ 300”] [“ Sam”,“ 300”] [“ Mike”,“ 100”] http ://sqlfiddle.com/#!9 / 94d33b / 1如何执行查询“ Amy”并列出“ Amy”的查询...
SELECT t2.*
FROM sourcetable t1
CROSS JOIN sourcetable t2
WHERE t1.name = 'Amy' -- criteria
ORDER BY t2.name = t1.name DESC, -- criteria first
t1.value = t2.value DESC; -- the same value next, another last