选择最近60天内没有购买的客户-PHP

时间:2019-02-14 07:52:51

标签: php

我有一个数据库,其锁定方式如下:

电子邮件/订购日期。

General :
Request URL: https://website.net/forum/dl.php?t=2508126
Request Method: GET
Status Code: 200 OK
Remote Address: 185.37.128.136:443
Referrer Policy: no-referrer-when-downgrade

Response Headers :
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Content-Type: text/html; charset=windows-1251
Date: Thu, 14 Feb 2019 08:03:29 GMT
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu, 14 Feb 2019 08:03:29 GMT
Pragma: no-cache
Server: nginx
Transfer-Encoding: chunked

Request Headers :
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Cookie: bb_t=a%3A3%3A%7Bi%3A2507902%3Bi%3A1550052944%3Bi%3A2508011%3Bi%3A1550120230%3Bi%3A2508126%3Bi%3A1550125516%3B%7D; bb_data=1-27969311-wXVPJGcedLE1I2mM9H0u-3106784170-1550128652-1550131390-3061288864-1
Host: website.net
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3701.0 Safari/537.36

Query String Parameters :
t: 2508126

我必须选择过去60天内没有购买的客户电子邮件。

例如,“ client3@gmail.com”有3个订单,比2个订单早60天,而最近60天有1个订单,因此我必须排除此客户。我只需要提取过去60天内没有购买的客户。

client1@gmail.com 13-02-2018
client2@gmail.com 02-02-2018
client3@gmail.com 24-01-2019
client3@gmail.com 24-06-2018
client3@gmail.com 24-04-2018

我只能提取客户端1和2,而不是3。

1 个答案:

答案 0 :(得分:1)

您可以尝试使用MySQL DATEDIFF()

SELECT email,MAX(order_date) FROM your_tbl_name GROUP BY email HAVING DATEDIFF(CURDATE(), order_date) >= 60 ORDER BY email ASC