gpt4 book ai didi

php - mysql 和 php - 一次选择获得 3 个或更多表?

转载 作者:行者123 更新时间:2023-11-29 02:53:49 25 4
gpt4 key购买 nike

我想向我的用户展示他最近的事件。为此,我有 3 个表格,我想按新闻日期显示顺序。

例如:

You sell product Y (table sell)
UserX put your product Y in favorite list (table favorite)
You have a product question (table questions)
You sell product Y (table sell again)
...

所以我想从不同的表中获取用户事件(卖家)并为他显示此警报。是否可以?任何例子如何做到这一点?

表卖:

id
seller
customer
product_name
data

最喜欢的表:

product_id
seller
customer
data

表格问题:

product_id
seller
customer
question
answer
data

最佳答案

我假设期望输出中的 You 表示卖家,userX 表示客户。所以,我认为这对你有用:

select data,concat('You sell product ',product_name) as logs 
from sell
where seller = 'userid'
union all
select data,concat(customer,' put your product ',product_id,' in favourite list')
from favorite
where seller = 'userid'
union all
select data,concat('You have a product question')
from question
where seller = 'userid'
order by data desc

关于php - mysql 和 php - 一次选择获得 3 个或更多表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32813993/

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