【发布时间】:2014-12-16 17:55:12
【问题描述】:
我在 Mysql 中使用 php,当用户在 date_field 中选择月份和年份时,我需要运行特定的查询。 此查询返回由用户选择的月/年创建的所有记录,我不希望在 select 内的子句中关联天数。 由于我只需要月/年选择的记录,有什么方法可以在仅选择的月/年中定义吗?
这是我的 Mysql 语句,其中包含用户选择的变量 有两个与内部联接相关的表,因此我可以使用日期“抓取”记录:
$quer_mesano = "Select b.name AS Canal
from canal_canalvenda b
inner join meta_meta c On c.canal_canalvenda_id_c = b.id
And c.deleted = 0
where c.periodo = '$month_year' //Here is the date value I just need to put in month/year
And b.deleted = 0
Group by Canal order by 1";
谁能帮帮我?
【问题讨论】:
-
在您的架构中,列 c.periodo 是如何定义的? $month_year 是什么格式,能举个例子吗?
-
dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html,尤其是
date_format()。