我对sql查询有疑问:
我通过查询得到以下结果:
select distinct eb.event_type_id, eb.status from eid.event_backlog eb order by 1
|event_type_id|status |
|-------------|----------|
|1 |SUCCESS |
|2 |SUCCESS |
|2 |ERROR |
|3 |SUCCESS |
|3 |ERROR |
|4 |SUCCESS |
我想通过对现状的分析得出以下结论:
|event_type_id|count |
|-------------|-------|
|1 |1 |
|2 |2 |
|3 |2 |
|4 |1 |
但我看到的获得此结果的唯一方法是执行以下查询:
select
eb.event_type_id,
count(1)
from
(
select
distinct eb.event_type_id, eb.status
from
eid.event_backlog eb
order by
1) eb
group by
eb.event_type_id
我不喜欢使用嵌套查询,有没有其他方法来获取我想要的?
1条答案
按热度按时间jq6vz3qz1#
简单
count(distinct eb.status)
,即。