本文介绍了如何计算表中具有相同列值的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下简单表格:
Suppose I have the following simple table:
create table mytable (
desid bigint not null,
ancid bigint not null
);
insert into mytable (ancid,desid) values (1,10);
insert into mytable (ancid,desid) values (1,20);
insert into mytable (ancid,desid) values (1,21);
insert into mytable (ancid,desid) values (1,22);
insert into mytable (ancid,desid) values (2,30);
insert into mytable (ancid,desid) values (3,40);
insert into mytable (ancid,desid) values (3,41);
insert into mytable (ancid,desid) values (3,42);
insert into mytable (ancid,desid) values (3,43);
什么是SQL命令,它将输出以下信息:
What is the SQL command that will print out the following information:
4 rows with ancid=1
1 rows with ancid=2
4 rows with ancid=3
推荐答案
您可以通过按 ancid
进行分组来获取信息:
You can get the information by grouping by the ancid
:
SELECT ancid, COUNT(*)
FROM mytable
GROUP BY ancid
这篇关于如何计算表中具有相同列值的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!