1

i have next query

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)

How can I remove duplicate query or reuse selection results? Maybe my request is completely incorrect?

1 Answer 1

1

I'm pretty sure your query is identical to:

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

SQL Fiddle demonstration

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.