具有案例条件的SQL查询? [英] Sql query with case condition?

查看:78
本文介绍了具有案例条件的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select  * from vOrderDetails D where OrderID = 65
select * from tblOrderReturns R where OrderID = 65







第一桌数据



OrderDetailsID订单ID productname



65 65 abc

21 65 ddf

20 65 asdf





桌面数据





OrderDetailsID订单ID



19 65

21 65





在这里我写这个查询






First Table Data

OrderDetailsID OrderID productname

19 65 abc
21 65 ddf
20 65 asdf


Second Table Data


OrderDetailsID OrderID

19 65
21 65


Here I write this query

select O.OrderID,D.OrderDetailID,D.ProductName,
case when R.OrderDetailID  != D.OrderDetailID then '0'
else '1'
end ReturnItem
From dbo.vOrderDetails D left outer Join tblOrders O On O.OrderID = D.OrderID
left outer join  tblCustomerLogins L On O.CustomerID = L.CustomerID
left outer join tblOrderReturns R on R.OrderID = D.OrderID
Where O.OrderID = 65 And L.SessionID ='8004837C7D62qdSV8'





现在我要显示三个colomn但我得到

6行

如何我可以这样做吗?



Now i want to display Three colomn but i get
6 rows
How can i do this?

推荐答案

如果我理解你的问题你的行太多了吗?



您提供的数据仅涵盖其中两个表。在您的查询中,您有4个表。所以很可能其中一个表导致行数增加或者你的加入字段存在问题(例如缺少字段)。



只是猜测基于表的名称,表 tblCustomerLogins 是否会导致额外的行?
If I understood your question correctly you get too many rows?

The data you provided covers only two of the tables. In your query you have 4 tables. So most likely one of the tables is causing the rows to multiply or you have a problem with the joining fields (missing field for example).

Just guessing based on the names of the tables, could the table tblCustomerLogins cause extra rows?


这篇关于具有案例条件的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆