2

私は SQL Server を初めて使用し、SQL Server を使用して次のシナリオのクエリを作成しようとしています。

使用できるGenericLabelsすべてのラベル ( ) のリストを含むという名前のテーブルがあります。varchar(30)それらは と呼ばれるテーブルで使用されますUserDeviceStatus。特定ので使用されているGenericLabelsが使用されていないラベルのリストが必要です。UserDeviceStatusUserId

次のクエリを作成しました

select label 
from GenericLabels 
where not exists (select customlabel from UserDeviceStatus where userid = 40)

このクエリは空の結果を返します

個々のクエリの出力を次に示します。

select label from GenericLabels

戻り値

Aux1
Aux2
Aux3
Aux4
Aux5
Aux6

select customlabel from userdevicestatus where userid = 40 

戻り値

Aux2
Aux3

次の結果が欲しい

Aux1
Aux4
Aux5 
Aux6
4

3 に答える 3

4

label と customlabel をリンクする必要があります。

select label from GenericLabels 
where not exists (
    select 1 from UserDeviceStatus 
    where customlabel = label 
    and userid = 40
)
于 2013-08-08T23:37:34.467 に答える
2

代わりにこれを試してください:

 select label from GenericLabels where label not in (select customlabel from UserDeviceStatus where userid = 40)
于 2013-08-08T23:37:48.480 に答える
-1
SELECT customlabel from userdevicesstatus where userid != 40

これにより、必要な結果が得られるはずです。

于 2013-08-08T23:39:56.803 に答える