SQL Server 2005 中的联合
以下是我的查询
Select vehicleID from trip where (StartingDate between ''+ convert(varchar(10), @StartDate,111) +'' and ''+ convert(varchar(10), @EndDate,111)+'')
or (enddate between ''+ convert(varchar(10), @StartDate,111) +'' and ''+ convert(varchar(10), @EndDate,111)+'')
or(StartingDate <= @StartDate and enddate >= @EndDate)
UNION
Select vehicleID from VehicleMaintenance where (FromDate between ''+ convert(varchar(10), @StartDate,111) +'' and ''+ convert(varchar(10), @EndDate,111)+'')
or (todate between ''+ convert(varchar(10), @StartDate,111) +'' and ''+ convert(varchar(10), @EndDate,111)+'')
or (FromDate <= @StartDate and todate >= @EndDate)
) as vehicle
如何从上面的查询结果中选择不同的vehicleId....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请注意,
UNION
将删除重复项(而UNION ALL
不会),因此您应该已经拥有唯一的车辆 IDNote that
UNION
will remove duplicates (whereasUNION ALL
will not), so you should already have unique vehicle ID's