sql隊伍的勝負狀況

1.數據顯示狀況sql

2.sql語句執行狀況數據庫

USE [數據庫名]
GO

/****** Object:  Table [dbo].[測試]    Script Date: 08/03/2017 10:58:02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[測試](
	[編號] [int] IDENTITY(1,1) NOT NULL,
	[日期] [datetime] NULL,
	[隊名] [nvarchar](50) NULL,
	[結果] [nvarchar](50) NULL,
 CONSTRAINT [PK_測試] PRIMARY KEY CLUSTERED 
(
	[編號] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


---若是勝的數量大於5請將此隊的排名標記爲冠軍團隊,不然標記爲亞軍團隊
select 隊名,(select COUNT(*) from 測試 a where 結果 = '勝' and a.隊名 = b.隊名) as 勝利次數,
(case when (select COUNT(*) from 測試 a where 結果 = '勝' and a.隊名 = b.隊名) > 5 then '冠軍團隊' else '亞軍團隊' end) as 榮譽 
from 測試 b group by 隊名
相關文章
相關標籤/搜索