これは私のview_remitです。私は欄month_paid
に欠けている月を決定する必要があります。mysqlの列に見つからない月を見つける方法は?
私は、このテーブルを取得するには、このコードを使用するが、私は行方不明の数ヶ月を決定する方法がわかりません。
SELECT RemitNo, PEN, Employer, month_paid, Total_PBR_Amt
FROM view_remit
JOIN (
SELECT 'JAN' as month_paid,'2016-01-01' as start,'2016-01-31' as end UNION ALL
SELECT 'FEB' as month_paid,'2016-02-01' as start,'2016-02-29' as end UNION ALL
SELECT 'MAR' as month_paid,'2016-03-01' as start,'2016-03-31' as end UNION ALL
SELECT 'APR' as month_paid,'2016-04-01' as start,'2016-04-30' as end UNION ALL
SELECT 'MAY' as month_paid,'2016-05-01' as start,'2016-05-31' as end UNION ALL
SELECT 'JUN' as month_paid,'2016-06-01' as start,'2016-06-30' as end UNION ALL
SELECT 'JUL' as month_paid,'2016-07-01' as start,'2016-07-31' as end UNION ALL
SELECT 'AUG' as month_paid,'2016-08-01' as start,'2016-08-31' as end UNION ALL
SELECT 'SEP' as month_paid,'2016-09-01' as start,'2016-09-30' as end UNION ALL
SELECT 'OCT' as month_paid,'2016-10-01' as start,'2016-10-31' as end UNION ALL
SELECT 'NOV' as month_paid,'2016-11-01' as start,'2016-11-30' as end UNION ALL
SELECT 'DEC' as month_paid,'2016-12-01' as start,'2016-12-31' as end
) M
ON view_remit.AP_From <= M.end
AND view_remit.AP_To >= M.start
ORDER BY PEN, AP_From
この出力を取得する必要があります。
|PEN|Employer|month|
| 1 | a | MAR |
| 1 | a | JUN |
| 1 | a | JUL |
| 1 | a | SEP |
| 1 | a | OCT |
| 1 | a | NOV |
何か助けていただければ幸いです。 ありがとうございます。
チェックこのリンクはあなたのアイデアを取得することがありhttp://stackoverflow.com/questions/27600863/mysql-monthly-sale-of-last-12-months-including-months-with-no-sale –
このような問題は、一般に、アプリケーションレベルのコードで最もよく処理されます。 – Strawberry