1.忘记写from
2.忘记分组:求每个人的积分总和要先把每个人先分组
3.有group by的情况下,select输出的只能是聚合函数/在group by 被分组的
4.order by,group by 用”,”逗号连接,不能用and连接
5.date_format后面没有e
6.日期类型经过 DATE_FORMAT()后变成 字符串,所以使用right()函数取后两位即为月数
7.group by可以用窗口函数代替
8.求最早两次下单的日期
善用max(date) min(date)
select tmp2.user_id, min(tmp2.date), max(tmp2.date), tmp2.cntfrom(select tmp1.user_id, tmp1.date, tmp1.cntfrom(select user_id, date, rank() over(partition by user_id order by date) rankNo,count(*) over(partition by user_id) cntfrom order_infowhere date>'2025-10-15' and order_info.status = 'completed'and order_info.product_name in('C++','Java','Python')) tmp1where tmp1.cnt>1 and rankNo<=2) tmp2group by tmp2.user_idorder by tmp2.user_id;
