gpt4 book ai didi

sap-commerce-cloud - 使用三个表的灵活搜索查询

转载 作者:行者123 更新时间:2023-12-01 10:22:26 25 4
gpt4 key购买 nike

我有三个表 Order、Customer、Address。

编辑:

我想获取所有在网站上注册的客户。 如果客户下了任何订单,我想从订单列表中获取最新订单, 如果客户没有下任何订单,那么我想将该字段留空,如下表所示

For eg :

Customer_Name Email ID Country Phone Latest_Order_Code
A xxxx xxxx x 1234

B yyyy yyyy y

C ffff tttt l 3456

D zzzz iiii o

如有任何帮助,我们将不胜感激?

最佳答案

引用下面的查询,我只获取订单代码和客户名称。您可以根据需要编写更多的连接和选择字段。

select {o.code} as orderCode,
{c.name} as name,
{a.cellphone} as cellphone

from {order as o
join Customer as c on {c.pk} = {o.user}
join Address as a on {o.deliveryaddress} = {a.pk}
}

where {o.code} in ({{select max({code}) from {order} group by {user}}})

更新:获取所有注册客户及其最后的订单信息

select t1.name, t2.orderCode, t2.cellphone

from

({{
select {pk} as userPk, {name} as name from {Customer}
}}) as t1

LEFT JOIN

({{
select
{o.code} as orderCode,
{o.user} as user,
{a.cellphone} as cellphone

from {order as o
join Address as a on {o.deliveryaddress} = {a.pk}
}

where {o.code} in ({{select max({code}) from {order} group by {user}}})
}}) as t2

on t2.user = t1.userPk

详细帖子how to write complex flexible search query join using the dynamic tables?

关于sap-commerce-cloud - 使用三个表的灵活搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49606062/

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