ゲームキー、チーム化、最終スコアの 3 つの列を持つデータベースを用意します。各ゲームキーのスコア差を見つけようとしています。
ゲームキー。チーム化。ファイナルスコア 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()
)