SQL遍历返回结果的最佳方法

编程入门 行业动态 更新时间:2024-10-28 10:24:04
本文介绍了SQL遍历返回结果的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试练习SQL技能,我有这样的模式:

I am trying to practice my SQL skills, I have this schema:

然后我想到了这个查询:

And i came up with this query:

SELECT vehicle_id FROM reservation WHERE NOT (pickup_date<='2017-05-20' AND end_date>='2017-05-15')

它将返回车辆ID的行,我希望能够使用这些车辆ID并从车辆表中返回车辆名称.怎么办呢?我听说过SQL连接会达到JOIN的目的吗?

it will return rows of vehicle_ids, I want to be able to use those vehicle ids and return vehicle_name from vehicle table. How to go about this? I have heard of SQL joins will a JOIN achieve this goal?

推荐答案

我不确定您要查询什么,但是如果要通过查询返回车辆ID和车辆名称,则应执行以下操作:

I am not sure of what you ask for, but if you want one query to return both the vehicle ids and the vehicle names, you should do this :

SELECT r.vehicle_id, v.vehicle_name FROM reservation r LEFT JOIN vehicle v ON r.vehicle_id = v.vehicle_id WHERE NOT (r.pickup_date<='2017-05-20' AND r.end_date>='2017-05-15')

这将返回两列:车辆ID之一和车辆名称之一.

This will return two columns : one of vehicle ids, and one of vehicle names.

(很抱歉法语单词"vehicule")

(sorry for the french word 'vehicule')

更多推荐

SQL遍历返回结果的最佳方法

本文发布于:2023-10-26 12:42:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:遍历   方法   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!