0

メンバーごとのチーム フィールドでの「a」の出現と日付の出現 (グループとして) の識別が必要です。データのサンプルは次のとおりです。

**member & date**|                    **Team**
a010112|                                  a
a010112|                                  b   
a010112|                                  c  
a010112|                                  d
b010112|                                  b
b010112|                                  b
c010112|                                  a
c010112|                                  b
c010112|                                  c

望ましい結果は次のとおりです。

**member & date|                   **team**|       **Occurrence of 'a' per member & date**
a010112|                                  a|             yes
a010112|                                  b|             yes
a010112|                                  c|             yes
a010112|                                  d|             yes
b010112|                                  b|             no
b010112|                                  b|             no
c010112|                                  a|             yes
c010112|                                  b|             yes
c010112|                                  c|             yes

計算フィールド - Occurrence of 'a' per member & date grouping は、case ステートメント / partition by / over を介したデータ ウェアハウス クエリからの計算フィールドになります。必要な構文について何らかの支援を提供できますか?

ありがとうございました、

4

1 に答える 1

1

これを試して

Declare @t Table ([Member and Date] Varchar(50), Team Varchar(10))
Insert Into @t Values
    ('a010112','a'),('a010112','b'),('a010112','c'),('a010112','d'),
    ('b010112','b'),('b010112','b'),
    ('c010112','a'),('c010112','b'),('c010112','c')

SELECT
    x.[Member and Date]
    ,x.[Team]   
    ,[Occurrence of 'a' per member & date] = CASE WHEN y.[Member and Date] IS NULL THEN 'No' ELSE 'Yes' END

From @t x
Left Join(Select Distinct [Member and Date]
     From @t Where Team = 'a')y
On x.[Member and Date] = y.[Member and Date]

ここに画像の説明を入力

于 2012-12-15T06:07:32.020 に答える