如何在SQL Server 2008中编写此查询?
我有一个表[dbo]。[产品]:如何在SQL Server 2008中编写此查询?,sql,sql-server,Sql,Sql Server,我有一个表[dbo]。[产品]: [id] [component] [quantity] 01----------A-------------2 02----------A-------------6 03----------A-------------8 04----------B-------------1 05----------B-------------2 06----------C-------------4 07----------C----------
[id] [component] [quantity]
01----------A-------------2
02----------A-------------6
03----------A-------------8
04----------B-------------1
05----------B-------------2
06----------C-------------4
07----------C-------------7
08----------C-------------5
09----------C-------------9
10----------C-------------3
11----------D-------------2
12----------D-------------7
我需要一个查询来查找这些记录:
[id] [component] [quantity]
05----------B-------------2
07----------C-------------7
09----------C-------------9
12----------D-------------7
您只需使用
和和或即可:
where (component = 'B' and quantity > 1) or
(component = 'C' and quantity > 5) or
(component = 'D' and quantity > 6)
您只需使用和和或即可:
where (component = 'B' and quantity > 1) or
(component = 'C' and quantity > 5) or
(component = 'D' and quantity > 6)