拥有一个包含三列的数据库 - 游戏密钥、团队合作、最终得分。我试图找到每个游戏键的分数差异。
游戏钥匙。联手。决赛成绩 16 27 21 16 7 24 17 22 17 17 21 10 18 15 9 18 11 3
期望输出将是
游戏钥匙。分数差异 16 3 17 7 18 6
看起来你想要差的绝对值,所以你可以使用;
SELECT Gamekey, max(Finalscore) - min(Finalscore) as Scorediff
FROM TableName
GROUP BY Gamekey
--为您运行的验证添加以下内容(假设以下内容已在 SQL Server 中进行了测试)
declare @testTable as table(Gamekey int, Teamed int, Finalscore int)
INSERT INTO @testTable values(16,27,21)
INSERT INTO @testTable values(16,7,24)
INSERT INTO @testTable values(17,22,17)
INSERT INTO @testTable values(17,21,10)
INSERT INTO @testTable values(18,15,9)
INSERT INTO @testTable values(18,11,3)
SELECT Gamekey, max(Finalscore) - min(Finalscore) as Scorediff
FROM @testTable
GROUP BY Gamekey
Create table Shop
(
ItemCode varchar(10)not null,
ShopName Varchar(50) not null,
Items varchar(50) not null,
Quantity int not null,
OrderDate datetime NOT NULL DEFAULT GETDATE(),
UpdateDate varchar(11)not null
)
GO
Create Table Product
(
ProductCode varchar(10)Primary key,
ShopName varchar(50),
Product varchar(50),
Quantity int ,
UnitPrice money ,
Defects int ,
Remainders int ,
TotalPrice money ,
Benefit money ,
OrderDate datetime NOT NULL DEFAULT GETDATE(),
UpdateDate varchar(11)
)
GO
Create Table ProductSold
(
ShopName varchar(50)not null,
Product varchar(50) not null,
Quantity int not null,
UnitPrice money not null,
TotalPrice money not null,
OrderDate datetime NOT NULL DEFAULT GETDATE()
)