gpt4 book ai didi

sql-server - Flag/Mark 最高排名记录

转载 作者:行者123 更新时间:2023-12-04 01:06:34 26 4
gpt4 key购买 nike

我有一个最终看起来像这样的查询:

DECLARE @Rank TABLE
(
Team VARCHAR(3),
StatCount TINYINT,
TeamRank TINYINT
)
INSERT INTO @Rank VALUES ('AAA', 10, 5)
INSERT INTO @Rank VALUES ('AAA', 7, 4)
INSERT INTO @Rank VALUES ('AAA', 6, 3)
INSERT INTO @Rank VALUES ('AAA', 4, 2)
INSERT INTO @Rank VALUES ('AAA', 2, 1)

SELECT * From @Rank ORDER BY TeamRank DESC

现在我的需求是标记最高排名,以便前端可以突出显示该记录。我对其他想法持开放态度,但一开始就尝试了这个,但它的表现并不像预期的那样。因此,如果您能指出我做错了什么或以其他方式提到,我将不胜感激。

SELECT 
Team,
StatCount,
TeamRank,
(
CASE
WHEN MAX(StatCount) = StatCount
THEN 'True'
ELSE
'False'
END
) AS 'HighScore'
FROM Rank
ORDER BY Team DESC;

谢谢

MY Mistake!

DDL 的每个条目都有“AAA”,但它们是不同的。应该是'AAA','BBB','CCC'等。

Thank You everyone for your answers. I apologize again for the bad DDL data.

最佳答案

尝试

SELECT 
Team,
StatCount,
TeamRank,
(
CASE
WHEN StatCount = (select max(StatCount) from @Rank)
THEN 'True'
ELSE
'False'
END
) AS 'HighScore'
FROM @Rank
ORDER BY Team DESC

关于sql-server - Flag/Mark 最高排名记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com