0

我有这样的mysql数据

production_date| production_net| worker_name
------------------------------------------
2013-01-10     | 390           | MMahe
------------------------------------------
2013-01-10     | 400           | RMaloney
------------------------------------------
2013-01-11     | 460           | JBurris
------------------------------------------
2013-01-11     | 210           | MMahe
------------------------------------------
2013-01-14     | 285           | LTaylor
------------------------------------------

我想这样显示我的结果

operator| 2013-01-10| 2013-01-11| 2013-01-14
--------------------------------------------
MMahe   | 390       | 210       |            
--------------------------------------------
RMaloney| 400       |           |            
--------------------------------------------
JBurris |           | 460       |            
--------------------------------------------
LTaylor |           |           | 285       
--------------------------------------------   

我将使用 php。

任何有用的帖子、想法或教程将不胜感激。

4

1 回答 1

1

你只能通过 MySQL 来做,看看这个链接http://www.artfulsoftware.com/infotree/qrytip.php?id=78

例如,将该链接中的示例查询修改为如下所示:

SELECT 
  EmpId,       
  sums.2005, sums.2006, sums.2007,      
FROM (                                  
  SELECT                                
    EmpID,
    SUM(IF(Yr=2005,sales,0)) As '2005',
    SUM(IF(Yr=2006,sales,0)) As '2006',
    SUM(IF(Yr=2007,sales,0)) As '2007'
  FROM Sales
  GROUP BY EmpID WITH ROLLUP
) AS sums; 

你会在 MySQL 中得到这样的结果

+--------+----------+----------+----------+
| EmpId  | 2005     | 2006     | 2007     |
+--------+----------+----------+----------+
| 1      | 12000.00 | 18000.00 | 25000.00 |
| 2      | 15000.00 |  6000.00 |     0.00 |
| 3      |     0.00 | 20000.00 | 24000.00 |
+--------+----------+----------+----------+
于 2013-01-21T20:23:30.623 回答