在sql中没有重复的代码

时间:2011-05-16 05:25:48

标签: mysql sql sql-server tsql

我的sql语句出了问题。它的符号代码必须没有重复。我将如何删除带有重复项的其他符号代码?

 SELECT     TOP (10) dbo.ltb_stockinfo.**SymbolCode**, dbo.stockInfoPrices.ChangePercent
 FROM       dbo.ltb_stockinfo INNER JOIN
            dbo.stockInfoPrices ON dbo.ltb_stockinfo.ID = dbo.stockInfoPrices.SymbolListId
WHERE     (dbo.ltb_stockinfo.NSCMarketSegment = N'NO')
GROUP BY dbo.ltb_stockinfo.SymbolCode, dbo.stockInfoPrices.ChangePercent
ORDER BY dbo.stockInfoPrices.ChangePercent DESC

非常感谢!

2 个答案:

答案 0 :(得分:2)

您不必使用max,min将工作甚至总和

SELECT     TOP (10) dbo.ltb_stockinfo.SymbolCode, MAX(dbo.stockInfoPrices.ChangePercent)
 FROM       dbo.ltb_stockinfo INNER JOIN
            dbo.stockInfoPrices ON dbo.ltb_stockinfo.ID = dbo.stockInfoPrices.SymbolListId
WHERE     (dbo.ltb_stockinfo.NSCMarketSegment = N'NO')
GROUP BY dbo.ltb_stockinfo.SymbolCode
ORDER BY MAX(dbo.stockInfoPrices.ChangePercent) DESC

答案 1 :(得分:1)

SELECT DISTINCT TOP 10 dbo.ltb_stockinfo.SymbolCode, ...