SQL:计算一对多关系

SQL: Counting one to many relations

给出下表:

假设每个用户只能选择一种颜色。你如何return(使用SQL)一个超过10个用户选择的颜色名称列表?

你试过吗?

select color_name  
from User U  
left join Color C on U.c_id = C.c_id  
group by color_name  
having count(u_id) >= 10