gpt4 book ai didi

php - mysql - 按间隔查询和/或不返回任何内容

转载 作者:行者123 更新时间:2023-11-29 02:55:33 24 4
gpt4 key购买 nike

我只需要从用户表中选择电子邮件,其中 weekly_mail(日期时间)早一周或为空,并且如果用户的积分加起来超过 10。它现在不返回任何内容.

points_plus表结构

id | user_id | points | date
1 62 5 2015-05-13 08:42:37
2 62 15 2015-05-14 03:12:32

查询

$q = "SELECT u.email, u.weekly_mail, SUM(p.points) AS points
FROM users u
LEFT JOIN points_plus p
ON u.id = p.user_id
WHERE points > 10 AND u.weekly_mail < NOW() - INTERVAL 1 WEEK OR u.weekly_mail = NULL
GROUP BY p.user_id";
$result = $this->db->mysqli->query($q);

if (!$result) {
printf("Query failed: %s\n", $this->db->mysqli->error);
exit;
}

$rows = array();
while($row = $result->fetch_row()) {
$rows[]=$row;
}

$result->close();
return $rows;

最佳答案

  SELECT u.email, u.weekly_mail, SUM(p.points) AS points
FROM users u
LEFT JOIN points_plus p
ON u.id = p.user_id
WHERE u.weekly_mail < NOW() - INTERVAL 1 WEEK OR u.weekly_mail = NULL
GROUP BY p.user_id having SUM(p.points) > 10

关于php - mysql - 按间隔查询和/或不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com