0

我有以下数据库:

Drager ||  Price
----------------
LP     ||  €16
CD     ||  €9 
LP     ||  €21
S      ||  €12

我想计算“Drager”并制作一个如下所示的表格:

Drager ||  Number  ||  Price
LP     ||  2       ||  €37
CD     ||  1       ||  €9
S      ||  1       ||  €12

我现在的问题是:我如何计算所有的“dragers”?

我收到了这个查询,但我怎样才能单独计算它们?:

$query = "SELECT COUNT(Medium) FROM platen";

我怎样才能得到总价?

我感谢您的帮助!

4

2 回答 2

3

应该很简单:

SELECT  Drager
      , COUNT(*) AS Number_of_Dragers
      , SUM(price) AS Price_of_Dragers
FROM    your_table
GROUP BY Drager 
于 2013-06-23T18:17:40.770 回答
1

我认为这就是您要寻找的东西;

$query = "SELECT drager, COUNT(drager),SUM(price) FROM platen GROUP BY drager";
于 2013-06-23T18:21:30.777 回答