This query runs perfectly. No errors. Clean logic. Looks correct. But the result is NOT reliable. Look closely at the query in the image. It tries to get the latest successful payment per customer using ROW_NUMBER(). Seems right… but there’s a hidden issue. When multiple payments happen on the same day, this query can return inconsistent results across runs. This is a classic production bug — everything works, but the output is non-deterministic. Your challenge: What is wrong with this query? How would you fix it? Comment your SQL below. Follow Data Rejected for real-world SQL challenges. Repost if this could help someone preparing for interviews or debugging production issues. Subscribe on YouTube for full SQL breakdowns. #SQL #DataEngineering #Analytics #DataAnalytics #LearnSQL #SQLTips #QueryOptimization #BigData #TechCareers #DataScience #DataRejected
First, this query contains syntax errors, regardless of the platform. Just look at the parentheses after ROW_NUMBER... So it is incorrect to claim that it runs properly, unless the SQL engine is overly permissive. Honestly, a question like this does not deserve an answer. And you name yourself a "Data Expert"?
Looks like an overkill query on top of poor table design.
Agile Delivery Lead | Scrum Practitioner | Azure Data Engineering | Technical Bussiness Analyst| Driving Scalable Data Platforms
2wApart from syntax errors, this query should fix if the bussiness question is payment amount per customer per day with latest data SELECT customer_id, payment_amount FROM ( SELECT customer_id, payment_amount, ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY payment_date DESC, payment_id DESC ) AS rn FROM payments WHERE status = 'success' ) t WHERE rn = 1; * payment_date should be time stamp