我想按照以下逻辑计算列出卖家,“列出过去15天内购买量为0且过去2个月购买量超过10件的卖家”
这是我的查询,我知道这个查询有问题,所以我需要帮助解决。
<Label Text="{Binding person.Age}" />
<Label Text="{Binding person.friend.Age}" />
答案 0 :(得分:0)
使用子查询,您可以执行以下操作:
select * from tsellers s
where
(select count(1) from torders o
where
o.seller_id=s.id and
order_date>DATE_SUB(curdate(), INTERVAL 15 DAY) ) < 1 and
(select count(1) from torders o
where
o.seller_id=s.id and
order_date>DATE_SUB(curdate(), INTERVAL 2 MONTH)) > 10;
子查询
(select count(1) from torders o
where
o.seller_id=s.id and
order_date>DATE_SUB(curdate(), INTERVAL 15 DAY) )
表示:在给定的时间内与该卖家有多少订单
您可以在rextester
上进行测试答案 1 :(得分:0)
可以使用下面提到的查询
SELECT c.* FROM sellers c
LEFT JOIN (
SELECT * FROM orders
WHERE order_date BETWEEN DATE(CURDATE() - INTERVAL 2 MONTH) AND NOW()
) d ON c.seller_id = d.seller_id
GROUP BY c.seller_id
HAVING count(d.order_id) >= 10
and c.seller_id in ((SELECT c.seller_id FROM sellers c
LEFT JOIN (
SELECT * FROM orders WHERE order_date BETWEEN DATE(CURDATE() - INTERVAL 15 DAY) AND NOW()
) as d
ON c.seller_id = d.seller_id
WHERE d.seller_id IS NULL))
因为您当前的查询是在过去15天内结合过去2个月获取数据