gpt4 book ai didi

mysql - 列出所有超过 2 个订单的客户 ID 和姓氏

转载 作者:行者123 更新时间:2023-11-28 23:43:56 25 4
gpt4 key购买 nike

我需要以下代码
客户表

CREATE TABLE customer (
customer_id INTEGER PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255),
city VARCHAR(50) NOT NULL,
State_ VARCHAR(50) NOT NULL,
zip VARCHAR(7) NOT NULL
)

订单表

CREATE TABLE order_(
order_number INTEGER PRIMARY KEY NOT NULL,
Customer_ID integer FOREIGN KEY REFERENCES customer (customer_id) Not NULL,
Date_ date NOT NULL,
)

如何显示超过 2 个订单的客户 ID 和姓氏请任何人帮忙

最佳答案

试试这个查询

Select customer_id,last_name From  Customer
Where customer_id in
(Select customer_id From Order group by customer_id having count(customer_id) > 2 )

关于mysql - 列出所有超过 2 个订单的客户 ID 和姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937944/

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