Why do these queries produce different results?
I am new to MySQL and have been trying to create a query that will return records with the lowest LTP per MarketName/SelectionName.
I have two different approaches but they return a different number of records when - to my beginner knowledge - they should return the same. The second query returns around 10% more records than the first.
There's nothing obvious in the data.
Can someone see what the issue is?
Thanks
First query:
WITH cte AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY MarketName, SelectionName ORDER BY LTP) AS rn,
COUNT(*) OVER (PARTITION BY MarketName, SelectionName) AS count
FROM r.`20224`
WHERE MarketState = 'Not In Play' AND SelectionID <> 0 AND CloseTime <> '' AND Result <> ''
)
SELECT * -- here you can select only the columns that you need
FROM cte
WHERE rn = 1 AND count > 900
Second query:
SELECT r.`20224`.*, null, null from r.`20224`,
(SELECT MarketName, SelectionName, MIN(`Date/Time`) AS `Date/Time` FROM r.`20224` WHERE MarketState = "Not In Play" AND SelectionID <> 0 AND CloseTime <> "" AND Result <> "" GROUP BY MarketName, SelectionName HAVING COUNT(*) > 900) min_LTP
WHERE r.`20224`.SelectionName=min_LTP.SelectionName
AND r.`20224`.`Date/Time`=min_LTP.`Date/Time`
Subject
Written By
Posted
Why do these queries produce different results?
March 03, 2023 09:22AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.