[英]SQL - select distinct from one column based on value from another column
I am looking to run a SQL query that counts the distinct values from one column based on the value of another column being equal to X. 我希望运行一个SQL查询,该查询基于另一列的值等于X来计算一列的不同值。
So for the below, I want to count the distinct values of the "value" column where the "field_number" column is equal to 2. 因此,对于以下内容,我想计算“ field_number”列等于2的“ value”列的不同值。
The result should return "2" (Australia and New Zealand) 结果应返回“ 2”(澳大利亚和新西兰)
select count(distinct value)
from your_table
where field_number = 2
You can use the below query 您可以使用以下查询
select count(distinct value) from my_table where field_number = 2;
Check here SQLFIDDLE DEMO 在这里检查SQLFIDDLE DEMO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.