sql – 查询计算不同值的数量?
发布时间:2020-12-12 06:33:42 所属栏目:MsSql教程 来源:网络整理
导读:我在MS Access 2003中有一个表,如下所示: *url id* example.com red example.com blue example.com blue other.com red other.com orange more.com blue 对于每个URL,我想知道有多少唯一ID.所以在这种情况下,结果应该是: *url count of distinct id* exampl
我在MS Access 2003中有一个表,如下所示:
*url id* example.com red example.com blue example.com blue other.com red other.com orange more.com blue 对于每个URL,我想知道有多少唯一ID.所以在这种情况下,结果应该是: *url count of distinct id* example.com 2 (because red and blue are the only values) other.com 2 more.com 1 这与SQL query to count number of different values非常相似,除了那种情况下的解决方案不起作用,因为它依赖于COUNT DISTINCT,但在Access中不支持.我试图在Access中寻找替代方法,但我害怕我不理解答案. 所以我想这个问题可以概括为“如何在msaccess中模拟计数明显”. 如果有人能给我一个提示,我将不胜感激. 解决方法这应该在MS Access 2003中工作(我刚测试过):SELECT url,count(id) as CountOfId FROM ( SELECT distinct id,url FROM yourtable ) x GROUP BY url 在这里,您可以在子查询中获得不同的id和url,然后计算该结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |