简体   繁体   English

选择最近“ z”天内从“ y”类别中购买“ x”次商品的所有客户

[英]Select all customer who have bought 'x' times something from the category 'y' within the last 'z' days

I have difficulties with the following statement: 我对以下陈述感到困难:

Select all customer who have bought 'x' times something from the category 'y' within the last 'z' days. 选择最近“ z”天内从“ y”类别中购买了“ x”次商品的所有客户。

The table contains 3 columns. 该表包含3列。 1. email address 2. category 3. timestamp 1.电子邮件地址2.类别3.时间戳

Any help would be much appreciated! 任何帮助将非常感激!

Thanks a lot! 非常感谢!

You can use below query for your criteria 您可以使用以下查询作为您的条件

SELECT category ,email,COUNT(*) purchases
FROM table
WHERE category  = 'y' 
AND `timestamp` >= TIMESTAMP(CURDATE() - INTERVAL z DAY)
GROUP BY email
HAVING purchases = 'x'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 表X中购买了表Y中所有产品的那些客户ID的列表? - list of those Customer IDs from Table X who have bought all of the products from Table Y? 遍历两个不同长度的POST数组,以找到购买x,y,z但不购买x,y,x,z的客户 - Iterating through two POST arrays of different length to find customers who bought x,y,z but didn't buy x,y,x,z 我需要找出从所有 4 个经销商处购买了 2 辆汽车的客户的姓名和客户 ID - I need to find out the name and customer id of customers who bought 2 cars from all the 4 dealerships 在 Mysql 中选择过去 5 天内没有记录时间的所有用户 - Select All users who has not logged their time in last 5 days in Mysql Select 客户未购买的产品 - Select Products NOT Bought by a Customer 如何让购买了 x 产品的客户也购买了 y 产品 - How to get the customers who bought x product also bought y product MySQL选择所有未登录30天的用户 - MySQL select all users who have not logged in for 30 days 对于每个客户,请选择购买相同商品的所有其他客户 - For every customer select all the other customers that bought the same item 选择过去5天内的所有数据 - Select all data from the last 5 days 列出所有已完成2个以上订单的客户ID和姓氏 - List all the customer IDs and last names who have made more than 2 orders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM