tem*_*pid 5 sql sql-server-2008
我有一张这样的桌子 -
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
Run Code Online (Sandbox Code Playgroud)
如何返回用户名称PropertyID = 13 AND PropertyVal='Business Development Analyst'AND PropertyID = 11 AND PropertyVal = 'Chicago'.如何为同一列执行多个where子句?
编辑:我需要结果集看起来像这样 -
Name
----
John Doe
Mike Smith
Run Code Online (Sandbox Code Playgroud)
不确定你到底想要什么。可能是
...
where (PropertyID = 13 AND PropertyVal = 'Business Development Analyst')
or (PropertyID = 11 AND PropertyVal = 'Chicago')
Run Code Online (Sandbox Code Playgroud)
或者
...
where PropertyID in (13, 11)
and PropertyVal in ('Business Development Analyst', 'Chicago')
Run Code Online (Sandbox Code Playgroud)
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
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52486 次 |
| 最近记录: |