本文介绍了我怎么...试着获得最后一次旅行车辆的身份。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得最后一次旅行车辆的身份证明。但是子查询给出了错误
I want to get Id of last journey vehicle. But subquery gives the error
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
如何解决这个问题。
我的尝试:
How solve this problem.
What I have tried:
select [dbo_pibm].[tbl_Vehicle].Id,
[dbo_pibm].[tbl_Vehicle].[Vehicle_Type],
[dbo_pibm].[tbl_Vehicle].Vehicle_No,
[dbo_pibm].[tbl_User].User_firstname+' '+[dbo_pibm].[tbl_User].User_surname as driver,[dbo_pibm].[tbl_Vehicle_Journey].Start_Place + ' To ' +[dbo_pibm].[tbl_Vehicle_Journey].End_Place as Journey,
CONVERT(VARCHAR(8),Start_Time,108) as Start_Time,
CONVERT(VARCHAR(8),End_Time,108)as End_Time,CONVERT(VARCHAR(108),
Journey_Date,103) as Journey_Date,
[dbo_pibm].[tbl_Vehicle_Journey].Id as TravelId
from [dbo_pibm].[tbl_Vehicle]
left outer join [dbo_pibm].[tbl_Vehicle_Journey]
on [dbo_pibm].[tbl_Vehicle].Id=[dbo_pibm].[tbl_Vehicle_Journey].Vehicle_Id
left outer join [dbo_pibm].[tbl_User]
on [dbo_pibm].[tbl_User].User_id=[dbo_pibm].[tbl_Vehicle_Journey].Driver
where [dbo_pibm].[tbl_Vehicle].[Id]=(select Vehicle_Id from [dbo_pibm].[tbl_Vehicle_Journey]
group by Vehicle_Id HAVING MAX(Id)>0)
推荐答案
select Vehicle_Id from [dbo_pibm].[tbl_Vehicle_Journey] group by Vehicle_Id HAVING MAX(Id)>0
独立运行,看看会有多少结果。如果有不止一个,那就是问题所在。使其正确返回一个值。
Run this independently and see how many results are coming. If more than one are coming, then this is the issue. Make it correct to return one value only.
这篇关于我怎么...试着获得最后一次旅行车辆的身份。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!