The query (below) will show date as a calender view with years as a row and months as column.
Result:
YEAR | JAN | FEB | MAA | APR | MEI | JUN | JUL | AUG | SEP | OKT | NOV | DEC |
---|
2012 | 5 | 1 | 3 | 6 | 4 | 4 | 2 | 5 | 7 | 2 | 4 | 7 |
2013 | 9 | 3 | 2 | 4 | 3 | 4 | 7 | 1 | 3 | 8 | 3 | 7 |
2014 | 8 | 5 | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) | (null) |
CREATE TABLE fundperformance
( `id` int auto_increment primary key,
`fund_id` int,
`date` date,
`performance` decimal(8,4))
SELECT YEAR(p.`date`) AS Year,
ROUND(MAX(case when month(p.`date`)= 1 then p.`performance` end),2) AS Jan,
ROUND(MAX(case when month(p.`date`)= 2 then p.`performance` end),2) AS Feb,
ROUND(MAX(case when month(p.`date`)= 3 then p.`performance` end),2) AS Mar,
ROUND(MAX(case when month(p.`date`)= 4 then p.`performance` end),2) AS Apr,
ROUND(MAX(case when month(p.`date`)= 5 then p.`performance` end),2) AS May,
ROUND(MAX(case when month(p.`date`)= 6 then p.`performance` end),2) AS Jun,
ROUND(MAX(case when month(p.`date`)= 7 then p.`performance` end),2) AS Jul,
ROUND(MAX(case when month(p.`date`)= 8 then p.`performance` end),2) AS Aug,
ROUND(MAX(case when month(p.`date`)= 9 then p.`performance` end),2) AS Sep,
ROUND(MAX(case when month(p.`date`)=10 then p.`performance` end),2) AS Oct,
ROUND(MAX(case when month(p.`date`)=11 then p.`performance` end),2) AS Nov,
ROUND(MAX(case when month(p.`date`)=12 then p.`performance` end),2) AS 'Dec'
FROM `fundperformance` p
WHERE p.`fund_id` = 1
GROUP BY 1
To present the data like this would be much better (imo) then a the default grid/crud.
How to create this query in a model or dsql?
And would it be possible to show this in a grid? or is it better to create a view or use a template?
Any suggestions on how to this (best) in ATK4 are more then welcome.