Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQL Server 2008中编写此查询?_Sql_Sql Server - Fatal编程技术网

如何在SQL Server 2008中编写此查询?

如何在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----------

我有一个表[dbo]。[产品]:

[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  
我需要一个查询来查找这些记录:

  • ‘B’、‘C’、‘D’和
  • B>1和B的数量
  • C>5和
  • D>6的数量
  • 结果应该是:

    [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)