首页 > 试题广场 >

牛客的课程订单分析(一)

[编程题]牛客的课程订单分析(一)
  • 热度指数:74676 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解

有很多同学在牛客购买课程来学习,购买会产生订单存到数据库里

有一个订单信息表(order_info),简况如下:

id user_id product_name
status
client_id
date
1 557336
C++
no_completed
1 2025-10-10
2 230173543
Python
completed
2 2025-10-12
3 57 JS
completed
3 2025-10-23
4 57 C++
completed
3 2025-10-23
5 557336
Java
completed
1 2025-10-23
6 557336
Python
no_completed
1 2025-10-24


1行表示user_id557336的用户在2025-10-10的时候使用了client_id1的客户端下了C++课程的订单,但是状态为没有购买成功。

2行表示user_id230173543的用户在2025-10-12的时候使用了client_id2的客户端下了Python课程的订单,状态为购买成功。

。。。

最后1行表示user_id557336的用户在2025-10-24的时候使用了client_id1的客户端下了Python课程的订单,状态为没有购买成功。

请你写出一个sql语句查询在2025-10-15以后状态为购买成功的C++课程或者Java课程或者Python的订单,并且按照order_info的id升序排序,以上例子查询结果如下:
id user_id product_name status client_id date
4 57 C++ completed 3 2025-10-23
5 557336 Java completed 1 2025-10-23
示例1

输入

drop table if exists order_info;
CREATE TABLE order_info (
id int(4) NOT NULL,
user_id int(11) NOT NULL,
product_name varchar(256) NOT NULL,
status varchar(32) NOT NULL,
client_id int(4) NOT NULL,
date date NOT NULL,
PRIMARY KEY (id));

INSERT INTO order_info VALUES
(1,557336,'C++','no_completed',1,'2025-10-10'),
(2,230173543,'Python','completed',2,'2025-10-12'),
(3,57,'JS','completed',3,'2025-10-23'),
(4,57,'C++','completed',3,'2025-10-23'),
(5,557336,'Java','completed',1,'2025-10-23'),
(6,557336,'Python','no_completed',1,'2025-10-24');

输出

id|user_id|product_name|status|client_id|date
4|57|C++|completed|3|2025-10-23
5|557336|Java|completed|1|2025-10-23
How are you doing?
select
    *
from
    order_info
where
    status = 'completed'
    and product_name in('C++','Java','Python')
    and date > '2025-10-15'
order by
    id asc

发表于 2025-05-28 20:49:41 回复(0)
select *
FROM order_info
WHERE product_name IN("C++","Java","Python")
AND status="completed"
AND date>"2025-10-15"
ORDER BY id
发表于 2025-02-16 19:21:07 回复(0)
select *
from order_info
where date>"2025-10-15" 
       and status = "completed"
       and product_name in ("C++","Python","Java")
order by id

发表于 2024-10-23 10:43:59 回复(0)

入门题目吧,主要在于where条件

select *
from order_info
where 
date >= '2025-10-15'
and product_name in ('C++', 'Java', 'Python')
and status = 'completed'
发表于 2024-08-13 17:45:21 回复(0)
select * from order_info
where datediff(date, '2025-10-15') > 0
and product_name in ('C++', 'Java', 'Python')
and status = 'completed'
order by id;

发表于 2024-07-29 23:59:48 回复(0)
select
    *
from order_info
where date>'2025-10-15' and status='completed' and (product_name in ('C++','Java','Python'))
发表于 2024-06-05 17:02:58 回复(0)
select * from order_info
where date>'2025-10-15' 
and status='completed' 
and product_name in ('C++','Java','Python')
order by id;

发表于 2024-02-05 14:07:02 回复(0)
select * 
from order_info
where date > '2025-10-15' 
    and status = 'completed' 
    and product_name in ('Java','C++','Python');
发表于 2024-01-22 21:41:50 回复(0)
select * 
from order_info
where date > '2025-10-15'
and status='completed'
and product_name in('C++','Java','Python')
order by id
发表于 2024-01-15 15:19:23 回复(0)
简单题
# 简单题
select  *
from order_info
where status="completed"
and product_name in ("C++","Java","Python")
and date>date("2025-10-15")
order by id asc


发表于 2023-03-24 08:17:07 回复(0)
-- 哪位大佬能告诉我一下,我还缺少了什么?用例不能通过
select * from order_info 
where date > '2025-10-15'
and status = 'completed'
and product_name in'C++','Java','Pythen'
ORDER BY id;
发表于 2022-12-09 16:44:36 回复(1)
select * from order_info
where((product_name = 'C++' and status = 'completed')
or (product_name ='Java'and status = 'completed'
or (product_name = 'Python'and status = 'completed'))
and date >'2025-10-15'
order by id asc;
发表于 2022-10-14 17:12:47 回复(0)
select *
from order_info
where date >'2025-10-15'
and status = 'completed'
and product_name regexp 'C++|Java|Python'
order by id

发表于 2022-09-08 17:38:45 回复(0)
发表于 2022-08-07 21:47:54 回复(0)
select *
from order_info
where date > '2025-10-15' and product_name in ('C++','Java','Python') and status = 'completed'
order by id
;

发表于 2022-07-12 13:45:54 回复(0)
select *
from order_info 
where status='completed' and date>'2025-10-15' and
product_name in ('C++','Java','Python')
order by id

发表于 2022-06-27 16:42:52 回复(0)
select *
from order_info
where product_name in ('C++','Java','Python') and status = 'completed' and datediff(date,'2025-10-15') > 0
order by id;
发表于 2022-06-14 11:48:42 回复(0)
select * from order_info 
where date>='2025-10-15' and status = 'completed' and product_name in ('C++','Java','Python') 
order by id asc 
发表于 2022-05-22 13:37:35 回复(0)