我有下一个查询
SELECT *
FROM(
SELECT
ID,
SUM(points) AS SUMMARY
FROM my_table
GROUP BY ID
ORDER BY SUMMARY DESC
) t1
WHERE SUMMARY>=(SELECT
SUMMARY
FROM (
SELECT
ID,
SUM(points) AS SUMMARY
FROM my_table
GROUP BY ID
ORDER BY SUMMARY DESC
) t2
WHERE ID=1234)
如何删除重复查询或重复使用选择结果? 也许我的要求完全不正确?
答案 0 :(得分:1)
我很确定您的查询与以下内容相同:
SELECT ID, SUM(points) AS SUMMARY
FROM my_table
GROUP BY ID
HAVING SUMMARY >= (SELECT SUM(points) FROM my_table WHERE ID=1234)
ORDER BY SUMMARY DESC