小明需要处理某支付app会在客户端打印的日志。其中客户端有表user_client_log(trace_id,uid,logtime,step,product_id,pay_method)分别代表trace_id订单号,uid(用户id)、logtime(客户端事件发生时间)、step(客户端步骤)、product_id(商品id)、pay_method(支付方式), 例如:完整的下单流程是select选择支付方式、order下单、start开始支付、failed支付失败、end支付结束)。 其中有product_info(product_id,price,type,product_name)分别代表product_id商品id、price商品价格、type商品类型、product_name商品名称(表中数据已去重)。 【问题】需要计算订单下单最多的商品id,取第一个返回即可;注最早支付的订单是只需要考虑order_log中的订单号的订单,非整条支付链路;相同次数以product_id顺序排列 【示例结果】返回两列:product_id、cnt代表个数 【示例解析】 1.例如trace_id为0001的支付链路日志,具有order信息(即step含有order) 2.根据含有order的订单与商品信息表中的商品信息关联得到,trace_id='0001'的订单,购买的商品是p100 3.根据1&2中汇总的数据分组统计最后得出下单成功最高的商品id
示例1
输入
DROP TABLE IF EXISTS `user_client_log`;
CREATE TABLE IF NOT EXISTS `user_client_log`(
trace_id varchar(255) NOT NULL,
uid varchar(32) DEFAULT NULL,
logtime varchar(32) DEFAULT NULL,
step varchar(32) DEFAULT NULL,
product_id varchar(32) DEFAULT NULL,
pay_method varchar(32) DEFAULT NULL,
UNIQUE uni_trace(trace_id,step)
);
DROP TABLE IF EXISTS `product_info`;
CREATE TABLE IF NOT EXISTS `product_info`(
product_id varchar(32) NOT NULL,
price int(32) DEFAULT 0,
type varchar(32) NOT NULL,
product_name varchar(255) NOT NULL,
UNIQUE uni_product(product_id)
);
INSERT IGNORE `user_client_log` VALUES
('0001','user_0001','2022-01-01 00:00:00','select','p100','wx'),
('0001','user_0001','2022-01-01 00:00:04','order','p100',''),
('0001','user_0001','2022-01-01 00:00:04','start','p100',''),
('0001','user_0001','2022-01-01 00:00:08','end','p100',''),
('0002','user_0002','2022-01-01 10:00:00','select','p599','alipay'),
('0002','user_0002','2022-01-01 10:00:00','order','p599',''),
('0002','user_0002','2022-01-01 10:00:01','start','p599',''),
('0002','user_0002','2022-01-01 10:00:10','failed','p599',''),
('0003','user_0003','2022-01-01 10:00:00','select','p599','alipay'),
('0003','user_0003','2022-01-01 10:00:00','order','p599',''),
('0004','user_0004','2022-01-01 10:00:00','select','p100','wx'),
('0004','user_0004','2022-01-01 10:00:00','order','p100',''),
('0004','user_0004','2022-01-01 10:00:01','start','p100',''),
('0005','user_0005','2022-01-01 10:00:00','select','p100','meituan'),
('0005','user_0005','2022-01-01 10:00:00','order','p100',''),
('0005','user_0005','2022-01-01 10:00:01','start','p100',''),
('0006','user_0006','2022-01-01 10:00:00','select','p599','alipay'),
('0006','user_0006','2022-01-01 10:00:00','order','p599',''),
('0006','user_0006','2022-01-01 10:00:01','start','p599','');
INSERT IGNORE `product_info` VALUES
('p100',100,'shoes','anta'),
('p599',5000,'telephone','huawei'),
('p233',2,'water','wahaha');
加载中...