关闭。这个问题需要细节或清晰。它目前不接受答案。**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。
10个月前关门了。改进这个问题我有这样的数据:
Table:City TypeBerlin EmployeeBerlin CustomerBerlin SupplierLondon EmployeeMadrid Employee
Table:
City Type
Berlin Employee
Berlin Customer
Berlin Supplier
London Employee
Madrid Employee
... 等等我想知道哪些城市至少有一名员工、客户或供应商。我不确定如何构造聚合函数来实现这一点?非常感谢!
rkue9o1l1#
你可以使用聚合函数
select city , sum(case when type = 'Employee' then 1 else 0 end) emp , sum(case when type = 'Customer' then 1 else 0 end) cust , sum(case when type = 'Supplier' then 1 else 0 end) suppfrom my_table group by city
select city
, sum(case when type = 'Employee' then 1 else 0 end) emp
, sum(case when type = 'Customer' then 1 else 0 end) cust
, sum(case when type = 'Supplier' then 1 else 0 end) supp
from my_table
group by city
检查值(至少一个)
select city , sum(case when type = 'Employee' then 1 else 0 end) emp , sum(case when type = 'Customer' then 1 else 0 end) cust , sum(case when type = 'Supplier' then 1 else 0 end) suppfrom my_table group by cityhaving emp +cust+supp > 0
having emp +cust+supp > 0
1条答案
按热度按时间rkue9o1l1#
你可以使用聚合函数
检查值(至少一个)