我是使用plsql查询Oracle的新手。假设我有以下数据集:
Doctor | Patient
A | John
A | Amy
B | Alex
B | Jane
B | Brian
如何对患者进行计数,数据将变为:
Doctor | Count of Patient
A | 2
B | 3
我认为查询应该是这样的:
select doctor, count(patient)
from table A
答案 0 :(得分:3)
select
doctor, count(*)
from
tablea
group by doctor
答案 1 :(得分:2)
在这里完全猜测......最好是伪造的代码
select (columns), a.counter
from yourcurrentjoins
inner join (select
doctor, count(*) as counter
from
tablea
group by doctor) a
on yourcurrentjoin.doctor = a.doctor
这将允许您在选择语句中将a.counter作为列引用...在添加所需的计数列时保留原始逻辑和所需的所有列。