I have a table TEMP
with columns Ticker
, Date
and Price
:
Ticker Date price
----------------------------
ABC 01/01/13 100.00
ABC 01/02/13 101.50
ABC 01/03/13 99.80
ABC 01/04/13 95.50
ABC 01/05/13 78.00
XYZ 01/01/13 11.50
XYZ 01/02/13 12.10
XYZ 01/02/13 12.10
XYZ 01/03/13 17.15
XYZ 01/04/13 14.10
XYZ 01/05/13 15.55
Note that I have a duplicate for XYZ on 01/02/13
I'm trying to identify dupes using the COUNT
and DISTINCT
statements in SQL, but I am having problems.
Here's my code and the error msg:
SELECT
Date,
Price,
COUNT([Ticker])
FROM
(SELECT DISTINCT
Ticker, Date
FROM
[Coinmarketcap].[dbo].[temp]
WHERE
COUNT[Ticker] > 1) AS dt
Error:
Incorrect syntax near 'Ticker'.
What's the best way to identify duplicate entries for each ticker/date?
I think you are looking for:
SELECT Ticker, Date, Price, COUNT(*)
FROM [Coinmarketcap].[dbo].[temp] t
GROUP BY Ticker, Date, Price
HAVING COUNT(*) > 1;
At least, this identifies the duplicate as you have defined it in your question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.