获取mysql和php中不同用户的总值[关闭]

table 1

|-----|---------------|---------------------|
| id  | name          |         pid         |
|-----|---------------|---------------------|
| 1   |  ram          |          2          |
| 2   |  rani         |          1          |
| 3   |   ram         |          3          |
|-------------------------------------------|

table 2

|-----|---------------|---------------------|
| pid | name          |         price       |
|-----|---------------|---------------------|
| 1   |  soap         |          2000       |
| 2   |  towel        |          1333       |
| 3   |  bed          |          3000       |
|-------------------------------------------|

i need result like this given below table

|-----|---------------|---------------------|
| id  | name          |         price       |
|-----|---------------|---------------------|
| 1   |  ram          |          4333       |
| 2   |  rani         |          2000       |
|-------------------------------------------|
SELECT  MIN(a.ID) ID, a.name, SUM(b.Price) Price
FROM    table1 a
        INNER JOIN table2 b
            ON a.PID = b.PID
GROUP   BY a.Name

OUTPUT

╔════╦══════╦═══════╗
║ ID ║ NAME ║ PRICE ║
╠════╬══════╬═══════╣
║  1 ║ ram  ║  4333 ║
║  2 ║ rani ║  2000 ║
╚════╩══════╩═══════╝