gpt4 book ai didi

mysql - SQL从4个表中选择数据

转载 作者:行者123 更新时间:2023-11-29 22:23:25 26 4
gpt4 key购买 nike

我想从 4 个表中选择数据。我有:

transactions: no_transactions, date, quantity, no_tank, id_cards, no_terminal
tanks: no_tank, type , price, temperature
terminals: no_terminal, location
cards: id_card , no_card , id_person
people: id_person , first_name, last_name

我想从交易中选择所有 no_transactions、日期、数量,储 jar 的类型、价格、温度,其中 tansk.no_tank = transactions.no_tank终端位置,其中terminals.no_terminal = transactions.no_terminal名字、姓氏来自 people.id_person = cards.id_person(但必须是 cards.id_card = transactions.id_cards)。

我该怎么做?

我尝试这样做:

SELECT no_transactions, date, quantity FROM transactions
UNION
SELECT type , price, temperature FROM tanks WHERE tansk.no_tank = transactions.no_tank
UNION
SELECT location FROM terminals WHERE terminals.no_terminal = transactions.no_terminal
UNION
SELECT first_name, last_name FROM people WHERE people.id_person=(select id_person where cards.id_card = transactions.id_cards)

但它不起作用:(有人可以帮忙吗?

最佳答案

尝试使用以下查询

select no_transactions, date, quantity from transactions, type , price,
temperature,location,first_name, last_name from transactions AS TR
INNER JOIN tanks AS TK on (TR.no_tank=TK.no_tank)
INNER JOIN terminals As TM on (TR.no_terminal=TM.no_terminal)
INNER JOIN cards CD on (TR.id_card=CD.id_card)
INNER JOIN people P on (CD.id_person=P.id_person)
where your condition if you need.

关于mysql - SQL从4个表中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30502031/

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