8

私はこのようなテーブルを持っています-

RecordID   PropertyID       PropertyVal
--------------------------------------------------
3215            7           john doe
3215            11          Chicago
3215            13          Business Development Analyst
3216            7           jane doe
3216            11          Chicago
3216            13          Managing Director
3217            7           mike smith
3217            11          Chicago
3217            13          Business Development Analyst
3218            7           john smith
3218            11          Seattle
3218            13          Managing Director

。でユーザーの名前を返すにはどうすればよいですかPropertyID = 13 AND PropertyVal='Business Development Analyst'AND PropertyID = 11 AND PropertyVal = 'Chicago'。同じ列に対して複数のwhere句を実行するにはどうすればよいですか?

編集:私はこのように見える結果セットが必要です-

Name
----
John Doe
Mike Smith
4

5 に答える 5

7
select PropertyVal
from your_table
where PropertyID = 7
and RecordID in 
(
  select RecordID   
  from your_table
  where (PropertyID = 13 AND PropertyVal='Business Development Analyst')
     or (PropertyID = 11 AND PropertyVal = 'Chicago')
  group by RecordID   
  having count(distinct PropertyID) = 2
)
于 2012-11-14T19:15:27.863 に答える
4

正確に何が欲しいかわからない。おそらくどちらかです

...
where (PropertyID = 13 AND PropertyVal='Business Development Analyst')
   or (PropertyID = 11 AND PropertyVal = 'Chicago')

また

...
where PropertyID in (13, 11) 
and PropertyVal in ('Business Development Analyst', 'Chicago')
于 2012-11-14T19:15:26.880 に答える
1

JOIN句で行くことができます...

元:

 SELECT LIST_OF_COLUMNS FROM TBL1 T1 JOIN TBL2 T2
    ON T1.COL1=T2.COL1 AND 
    T1.COL2=T2.COL2 AND 
    T1.COL3=T2.COL3 AND 
    T1.COL4=T2.COL4 
于 2016-06-15T13:53:43.397 に答える
0
SELECT LIST_OF_COLUMNS FROM TBL1 T1 JOIN TBL2 T2
    ON T1.COL1=T2.COL1 AND 
    T1.COL2=T2.COL2 AND 
    T1.COL3=T2.COL3 AND 
    T1.COL4=T2.COL4 
于 2016-09-26T17:36:36.553 に答える
0

INTERSECT演算子の使用

select PropertyVal as "Name"
from mytable
where PropertyID=7
and RecordID in 
(
    select RecordID
    from mytable
    where PropertyID = 13 AND PropertyVal='Business Development Analyst'

    intersect

    select RecordID
    from mytable
    where PropertyID = 11 AND PropertyVal='Chicago'

)
于 2020-06-09T18:07:49.967 に答える