gpt4 book ai didi

php - 多表选择

转载 作者:行者123 更新时间:2023-12-03 01:34:24 25 4
gpt4 key购买 nike

我不知道这是否可能,但这就是我想做的。我有三张 table

账户

id | username | pass

汽车

id | plate | id_ac | kilometers // in the id_ac I add manual the id of the car's owner.

行程

id | plate | places | date | active

现在我希望当用户登录时查看他的汽车事件的行程。所以我想

SELECT from Trips the plate, places, date WHERE active=0 AND id= ? (the logged user's id)

但是表 trips 没有车主的 ID。所以我想以某种方式选择记录用户拥有的汽车的表 Trips 的值。

知道我该怎么做吗?

最佳答案

您应该看看表连接。这看起来就是您正在寻找的:

从行程中选择 t.plate、t.places、t.date 作为 t JOIN Cars as c ON t.plate = c.plate WHERE t.active = 0 AND c.id_ac = ?

看看这个。这是解释表连接的一个很好的方式。 http://www.sql-join.com/sql-join-types

我不会深入讨论数据库架构和更深层次的内容,但它可以帮助您完成手头的任务

关于php - 多表选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60031474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com