0
select case when exists(
select top 1 1
from dg_world_records wr (nolock)
where wr.gametypeid = 4
and wr.playerid = 1
)
then totaltime = (select min(totaltime) from dg_world_records (nolock) where playerid = 1 and gametypeid = 4)
else totaltime = (select max(totaltime) from dg_world_records (nolock) where gametypeid = 4)
end
我的猜測是這不能完成,但我想在sql case語句中做一個子選擇。這可能嗎?SQL案例聲明與子選擇
我試圖做基於發現或沒有找到在表中的值的查找。我可以通過分解聲明來做到這一點,但我想知道是否可以在一個聲明中做到這一點。
下面是表模式:
CREATE TABLE [dbo].[DG_WORLD_RECORDS](
[WorldRecordId] [int] IDENTITY(1,1) NOT NULL,
[GameTypeId] [int] NOT NULL,
[PlayerId] [int] NOT NULL,
[NumberOfValues] [int] NOT NULL,
[TotalTime] [int] NOT NULL,
[DateOfRecord] [datetime] NOT NULL,
[GameId] [int] NULL,
[UTCInserted] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCInserted] DEFAULT (getutcdate()),
[UTCUpdated] [datetime] NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_UTCUpdated] DEFAULT (getutcdate()),
[SrvName] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_DG_WORLD_RECORDSII_SrvName] DEFAULT (@@servername),
約束[PK_DG_WORLD_RECORDS] PRIMARY KEY CLUSTERED ( [WorldRecordId] ASC ) )
我承認這是「瘋狂查詢」我只是擴大我的SQL技能位。感謝您的幫助! – codingguy3000 2012-02-03 19:14:01
@ codingguy3000沒問題,很高興我能幫助! – 2012-02-03 19:23:22