Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.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 具有多个条件的Select语句_Sql_Sql Server - Fatal编程技术网

Sql 具有多个条件的Select语句

Sql 具有多个条件的Select语句,sql,sql-server,Sql,Sql Server,我正在处理一个现有的.net系统,我有一个SQL表,两个用户之间有“报价”。“offers”从usertype1到usertype2有两种方式(giggidy),反之亦然。为了使其“简单”,有一个“offertype”字段,它定义了报价的方向,以便正确的用户“接受”报价。当您想要查询它时,非常简单,如果您想要获取单个报价的数据,您可以非常轻松地执行查询。我的问题是: 我正在尝试构建一个视图,其中显示user1的所有产品列表。在此视图中,它应该显示所有“offertype1”的报价,其中user1

我正在处理一个现有的.net系统,我有一个SQL表,两个用户之间有“报价”。“offers”从usertype1到usertype2有两种方式(giggidy),反之亦然。为了使其“简单”,有一个“offertype”字段,它定义了报价的方向,以便正确的用户“接受”报价。当您想要查询它时,非常简单,如果您想要获取单个报价的数据,您可以非常轻松地执行查询。我的问题是:

我正在尝试构建一个视图,其中显示user1的所有产品列表。在此视图中,它应该显示所有“offertype1”的报价,其中user1是“offerloginuser”,以及所有“offertype2”的报价,其中user1是“offerrecipientuser”

我需要能够看到奥菲德的:1;2.3.4但不是5,因为user1不参与。乍一看,它看起来很简单,你有用户ID,问题是,系统的设计者选择了基于用户类型的用户ID使用单独的表,所以我可能有两个具有相同ID的用户

我有两个特别声明:

select * from tbl_offers where offertype = 1 and offerloginuserid = 1

每一个单独执行给我我需要的,是可以加入他们并显示所有的结果,还是我必须做一个加入?我正在将这些结果绑定到DevExpress网格,以便在登录时显示给用户。

这对您有帮助吗

select * from tbl_offers where (offertype = 1 and offerloginuserid = 1) OR (offertype = 2 and offerrecipientid = 1)
这能帮你吗

select * from tbl_offers where (offertype = 1 and offerloginuserid = 1) OR (offertype = 2 and offerrecipientid = 1)
请试试这个:-

select * from tbl_offers  
where offertype in (1,2) and offerrecipientid = 1
请试试这个:-

select * from tbl_offers  
where offertype in (1,2) and offerrecipientid = 1

UNION-ALL
可能会有帮助。
UNION-ALL
可能会有帮助。感谢Anup,但您忘记了一种类型的报价是offerrecipientid,另一种类型的报价是offerloginuserid@etsa已经回答了这个问题,我只是等着接受它。谢谢Anup,但你忘了一种报价是offerrecipientid,另一种是offerloginuserid@etsa已经回答了这个问题,我只是等着接受它。