【发布时间】:2015-02-04 23:01:10
【问题描述】:
Oracle 查询
select
courses.name,
count(gardener)
from
attendances
join courses using (course)
group by
courses.name
order by
count(gardener) asc
输出
╔═══════════╦═════════════════╗
║ NAME ║ COUNT(GARDENER) ║
╠═══════════╬═════════════════╣
║ Harvesting║ 3 ║
║ Planting ║ 3 ║
║ Gardening ║ 4 ║
╚═══════════╩═════════════════╝
我怎样才能显示最小/最大甚至平均计数。例如。最低限度
// I just want to display the courses with minimum count
╔═══════════╦═════════════════╗
║ NAME ║ COUNT(GARDENER) ║
╠═══════════╬═════════════════╣
║ Harvesting║ 3 ║
║ Planting ║ 3 ║
╚═══════════╩═════════════════╝
我试过了
select
max(cnt), -- min(cnt) and avg(cnt) doesnt seem to work
name
from
(
select
courses.name,
count(gardener) as cnt
from
attendances
join courses using (course)
group by
courses.name
order by
count(gardener) asc
)
group by
name
我得到无效的标识符“cnt”。我尝试使用 max(cnt) 它也给了我相同的标识符错误,任何人都可以更正我的语法并建议我做错了什么,或者建议一种不同的方法来做到这一点?
编辑:我已经删除了语音标记,但仍然显示所有记录,而不仅仅是我需要的最大值 count() 记录。
【问题讨论】: