我有一个EAV表,我的数据是
stageid, value, row
1 rob 1
2 01/01/2012 1
3 2000 1
1 Ben 2
2 ......... and so on
我必须将此数据转置/转换为可用格式,例如三列表
可怕的查询是
SELECT pearson,
Date_format(a.salesdate, '%Y-%m-01') AS monthYear,
Count(1)
FROM (SELECT row,
Group_concat(IF(stageid = 74, value, NULL)) AS 'pearson',
Group_concat(IF(stageid = 59, Str_to_date(value, '%d/%m/%Y'), NULL)) AS 'salesdate',
Group_concat(IF(stageid= 67, value, NULL)) AS 'salescount'
FROM stagingdata
GROUP BY row) AS a
WHERE a.pearson IS NOT NULL
AND a.pearson != ''
AND Year(a.salesdate) IN ( '2012', '2011' )
GROUP BY Trim(Lower(a.pearson)),
Date_format(a.salesdate, '%Y-%m')
HAVING Count(1) > 10
ORDER BY pearson, a.salesdate ASC
我得到了这个结果
Person, Date, Sales
Rob 2012-01-01 2000
Ben 2012-01-01 500
Ben 2012-03-01 300
Rob 2012-05-01 2000
我想使用NVD3创建堆积区域图表,但是你可以看到日期列中的数据是错误对齐的 - 我想我需要插入数据 - 但我不知道如何!
所以我的数据应该是
Person, Date, Sales
Rob 2012-01-01 2000
Ben 2012-01-01 500
Ben 2012-03-01 300
Rob 2012-03-01 0
Rob 2012-05-01 2000
Rob 2012-05-01 0
我是否在查询中执行此操作?用PHP<可能不是!因为我希望我的3柱图表php对json creator尽可能通用 - 或者你能在NVD3或D3中做到这一点