-4

結果が必要な2つのテーブルを比較して、2つのテーブルを提供しました。結果表は最後の表に示されています。表 a

|-----|---------------|---------------------|
| id  | name          |         pid         |
|-----|---------------|---------------------|
| 1   |  ram          |         EW2         |
| 2   |  rani         |         EW1         |
| 3   |  ram          |         EW3         |
| 4   |  rani         |         EW4         |
| 6   |  ram          |         EW5         |
|-------------------------------------------|

表b

|-----|---------------|-------|--------------|
| id  | name          |  pid  |  price       |
|-----|---------------|-------|--------------|
| 1   |  soap         |  EW1  |   2000       |
| 2   |  towel        |  EW2  |   1333       |
| 3   |  bed          |  EW3  |   3000       |
| 4   |  facewash     |  EW4  |    250       |
| 5   |  T.soap       |  EW5  |    300       |
|--------------------------------------------|

php mysqlを使用して、以下の表のような結果が必要です

|-----------------|-----------|---------------------|
| no of products  | name      |  total_ price       |
|-----------------|-----------|---------------------|
|       3         |  ram      |          4833       |
|       2         |  rani     |          2250       |
|---------------------------------------------------|
4

3 に答える 3

1
SELECT COUNT(b.id), a.name, SUM(b.price)
FROM a LEFT JOIN b ON a.pid=b.pid
GROUP BY a.name
于 2013-04-10T09:46:35.357 に答える
0
$query = " SELECT count(tableA.name) ,tableA.name,sum(tableB.price)
           FROM tableA
           INNER JOIN tableB 
              ON tableA.pid=tableB.pid
           GROUP BY tableA.name "
于 2013-04-10T09:52:10.003 に答える
0

SELECT COUNT(a.id) AS NO_OF_PRODUCTS, a.name AS NAME, SUM(b.price) AS TOTAL_PRICE FROM a LEFT JOIN b ON b.pid=a.pid GROUP BY a.name

于 2013-04-10T09:52:30.597 に答える