此查询选择所有拥有" user_expire"的用户。行" B1month"。
$oneMonthUsersData = mysql_query("SELECT username,email FROM user WHERE DATEDIFF(NOW(),date_created) > 30 AND user_expire = 'B1month'");
while ($oneMonthUsers = @mysql_fetch_array($oneMonthUsersData)) {
$deletedUsers = $deletedUsers.",".$oneMonthUsers['username'];
$deletedUsersEmails[] = $oneMonthUsers['email'];
}
如何格式化语法如果我希望同样的查询也选择所有拥有" user_expire"排" C1month"以及那些拥有" B1month"?
的人答案 0 :(得分:2)
您是否尝试过以下查询:
SELECT username,email FROM user WHERE DATEDIFF(NOW(),date_created) > 30 AND (user_expire = 'B1month' OR user_expire = 'C1month')
答案 1 :(得分:1)
SELECT username, email
FROM user
WHERE DATEDIFF(NOW(),date_created) > 30
AND user_expire IN('B1month', 'C1month')
OR
SELECT username, email
FROM user
WHERE DATEDIFF(NOW(),date_created) > 30
AND (user_expire = 'B1month' OR user_expire = 'C1month')
但是第一个代码有更好的性能,我认为