现在,其他程序员之一编写了此视图以显示 6 个月的间隔。我如何编写它以显示按月分组的 12 个月的间隔,但仅适用于 2011 年
我想将其复制为按月分组的 12 个月的单独视图,但仅适用于 2012 年
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%`
SQL SECURITY DEFINER VIEW `vw_dash_bymonth`AS
select
month(from_unixtime(`tbl_services`.`datetime`)) AS` month1`,
date_format(from_unixtime(`tbl_services`.`datetime`),'%Y') AS` year1`,
date_format(from_unixtime(`tbl_services`.`datetime`),'%d') AS `day1`,
`tbl_services`.`datetime` AS `realdate`,sum(`tbl_services`.`gallons`) AS `gallons`,
count(0) AS `service`,
round(avg(`tbl_services`.`gallons`),1) AS `average`
from `tbl_services`
where (from_unixtime(`tbl_services`.`datetime`) > (now() - interval 6 month))
group by month(from_unixtime(`tbl_services`.`datetime`))