首页 > 试题广场 >

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

[编程题]牛客的课程订单分析(一)
  • 热度指数:72956 时间限制: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
select * from order_info
where date >'2025-10-15'
and status='completed'
and(product_name ='C++'
   &nbs***bsp;product_name ='Java'
   &nbs***bsp; product_name ='Python')
order by id 

发表于 2021-08-18 17:41:20 回复(0)
# 简单,过,主要是条件和排序
select id, user_id, product_name, status, client_id, date
from order_info
where date > '2025-10-15'
and status = 'completed'
and product_name in ('C++','Python','Java')
order by id


发表于 2022-04-19 15:24:03 回复(0)

select * from 
(
select * from
(
select * from order_info
where date>'2025-10-15')t1
where t1.status='completed')t2
where t2.product_name in ('C++','Java','Python')
order by t2.id
发表于 2021-04-28 21:17:21 回复(2)
select id, user_id, product_name,status,client_id,date
from order_info
where date >"2025-10-15"
and (product_name = "C++" or product_name ="Java"
    or product_name = "Python")
and status = "completed"
order by id asc
发表于 2021-03-13 20:34:07 回复(0)
select *
from order_info
where datediff(date,"2025-10-15")>0
    and status = "completed"
    and product_name in("C++","Java","Python")
order by id
DATEDIFF(d1,d2) 语句---计算日期 d1->d2 之间相隔的天数。
编辑于 2021-03-11 17:47:52 回复(2)
第一个题目比较简单,是把所有的条件列出来就行了:
select * from order_info where date>'2025-10-15' and status='completed' and product_name in('C++','Java','Python') order by id;
最后要注意的是按照id升序排序
编辑于 2021-02-26 16:02:47 回复(0)
select *
from order_info
where status = 'completed' and date > '2025-10-15'
and product_name in ('C++','Java','Python')
order by id asc;
发表于 2021-06-01 15:46:23 回复(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

用datediff(date1, date2) > 0的形式筛选,找出2025-10-15以后的日期

编辑于 2021-02-27 09:34:48 回复(4)
select * from order_info
where date>'2025-10-15'
and status='completed'
and product_name in('C++','Java','Python')
order by id

编辑于 2021-02-27 16:38:48 回复(0)
select id
,user_id
,product_name
,status
,client_id
,order_info.date
from order_info
where (order_info.date>'2025-10-15') and (product_name='C++'&nbs***bsp;product_name='Java'&nbs***bsp;product_name='Python') and status='completed'
order by 1

发表于 2024-05-14 23:56:44 回复(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)
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 product_name in('c++','java','python') and status='completed'
order by id;
发表于 2025-02-01 19:34:36 回复(0)
select * 
from order_info 
where date>'2025-10-15' 
and status='completed' 
and product_name in('C++','Java','Python') 
order by id;

发表于 2024-11-27 15:42:45 回复(0)
select *
from order_info
where date>='2025-10-15' and status='completed'and product_name in('C++','Java','Python')
order by id asc

发表于 2024-10-30 17:59:11 回复(0)
SELECT
    id,
    user_id,
    product_name,
    status,
    client_id,
    date
FROM order_info
WHERE date > '2025-10-15' AND status = 'completed' AND product_name IN ('C++', 'Java', 'Python')
发表于 2024-10-26 15:38:23 回复(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)
select *
from order_info
where date > '2025-10-15' and status = 'completed' and product_name in ('C++', 'Python', 'Java')
order by id

发表于 2024-09-23 09:50:56 回复(0)
select id,user_id,product_name,status,client_id,date
from order_info
where status="completed" and product_name in("C++","Java","Python") and
date>="2025-10-15"
order by id
考察了where的多种用法
发表于 2024-08-30 23:06:23 回复(0)