0

谁能给我一些例子来进行查询,其中有多个 WHERE 语句?

我有以下查询,我想添加 WHERE privacy = 'public'

$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS 
day,eventContent,eventTitle,id FROM eventcal WHERE eventDate BETWEEN 
'$current_year/$current_month/01' AND '$current_year/$current_month
/$total_days_of_current_month'");

提前致谢。

4

4 回答 4

3

[..] WHERE privacy = 'public' AND (eventDate BETWEEN [..] )?

于 2010-01-18T15:15:51.173 回答
2

利用:

AND privacy = 'public'
于 2010-01-18T15:15:15.820 回答
2

我对 MySql 一无所知,但看起来你只需要另一个 AND 语句:

$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS day,eventContent,eventTitle,id FROM eventcal WHERE
eventDate BETWEEN '$current_year/$current_month/01'
AND '$current_year/ $current_month/$total_days_of_current_month'
AND privacy='public' ");

于 2010-01-18T15:19:05.827 回答
1

将 WHERE 更改为 AND:

AND privacy = 'public'

完整,并且更具可读性:

SELECT DATE_FORMAT(eventDate,'%d') AS day,
       eventContent,
       eventTitle,
       id
FROM   eventcal
WHERE  eventDate BETWEEN '$current_year/$current_month/01'
                     AND '$current_year/$current_month/$total_days_of_current_month'
AND    privacy = 'public'
于 2010-01-18T15:15:25.510 回答