【发布时间】:2022-12-14 09:25:05
【问题描述】:
我在 mySQL 中有这个查询,我想对每个医生的线产品求和,但我不知道该怎么做。
use avant_medical;
select
sales.doctor_id as DoctorID,
line_products.id as LineProductID,
line_products.name as LineProductName
from `doctors`
inner join `sales` on `doctors`.`id` = `sales`.`doctor_id`
inner join `inventories` on `sales`.`id` = `inventories`.`sale_id`
inner join `products` on `inventories`.`product_id` = `products`.`id`
inner join `line_products` on `products`.`lineProduct_id` = `line_products`.`id`
order by `doctors`.`id` asc;
lPID= lineProductID
|DrID|lPID |
| -- | ----|
| 1 | 7 |
| 1 | 6 |
| 1 | 6 |
| 1 | 7 |
| 1 | 7 |
| 1 | 7 |
| 1 | 6 |
This is how I want:
Doctor 1
lineID | quantity
7 | 4
6 | 3
我只在 mySQL 中尝试这个查询
【问题讨论】:
-
您需要提供架构以显示数据的存储方式
-
看起来你想要数数不是和但还不清楚。示例数据将帮助我们帮助您。
标签: mysql