私は次のコードを書いていますが、それ以前に使ったことがありますが、誰かがもっと良いやり方をしているのだろうかと思っていました。MySqlの今年の月の結果を返す
私は基本的に、日付が記された一連のデータから結果を返そうとしています。今年の月にフォーマットされた結果が必要です。
SELECT * FROM
(
SELECT
1 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()),'-01-01') AS `from`, CONCAT(YEAR(NOW()),'-01-31') AS `to`, 'January' AS `fullMonth`, 'Jan' AS `shortMonth`
UNION SELECT 2 AS `month`, YEAR(NOW()) AS `year` ,CONCAT(YEAR(NOW()), '-02-01') AS `from`, CONCAT(YEAR(NOW()), '-02-', DAY(LAST_DAY(CONCAT(YEAR(NOW()), '-02-01')))) AS `to`, 'February' AS `fullMonth`, 'Feb' AS `shortMonth`
UNION SELECT 3 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-03-01') AS `from`, CONCAT(YEAR(NOW()), '-03-31') AS `to`, 'March' AS `fullMonth`, 'Mar' AS `shortMonth`
UNION SELECT 4 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-04-01') AS `from`, CONCAT(YEAR(NOW()), '-04-30') AS `to`, 'April' AS `fullMonth`, 'Apr' AS `shortMonth`
UNION SELECT 5 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-05-01') AS `from`, CONCAT(YEAR(NOW()), '-05-31') AS `to`, 'May' AS `fullMonth`, 'May' AS `shortMonth`
UNION SELECT 6 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-06-01') AS `from`, CONCAT(YEAR(NOW()), '-06-30') AS `to`, 'June' AS `fullMonth`, 'Jun' AS `shortMonth`
UNION SELECT 7 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-07-01') AS `from`, CONCAT(YEAR(NOW()), '-07-31') AS `to`, 'July' AS `fullMonth`, 'Jul' AS `shortMonth`
UNION SELECT 8 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-08-01') AS `from`, CONCAT(YEAR(NOW()), '-08-31') AS `to`, 'August' AS `fullMonth`, 'Aug' AS `shortMonth`
UNION SELECT 9 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-09-01') AS `from`, CONCAT(YEAR(NOW()), '-09-30') AS `to`, 'September' AS `fullMonth`, 'Sep' AS `shortMonth`
UNION SELECT 10 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-10-01') AS `from`, CONCAT(YEAR(NOW()) ,'-10-31') AS `to`, 'October' AS `fullMonth`, 'Oct' AS `shortMonth`
UNION SELECT 11 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-11-01') AS `from`, CONCAT(YEAR(NOW()), '-11-30') AS `to`, 'November' AS `fullMonth`, 'Nov' AS `shortMonth`
UNION SELECT 12 AS `month`, YEAR(NOW()) AS `year`, CONCAT(YEAR(NOW()), '-12-01') AS `from`, CONCAT(YEAR(NOW()), '-12-31') AS `to`, 'December' AS `fullMonth`, 'Dec' AS `shortMonth`
) AS `dateFilter`
は、私たちがその周りに結果セットを構築することができるようにしかし、これは、クエリに加えて、迅速なペーストとして意図され、日 –