简体   繁体   English

如何计算 PostgreSQL 中列的每个不同值的出现次数?

[英]How can I do count on number of occurrences of each distinct value of a column in PostgreSQL?

List of students enrolled in courses.参加课程的学生名单。 In each course there could be x homeworks.每门课程可能有 x 个作业。 I need count of homeworks for each course for each student.我需要为每个学生计算每门课程的作业。

Eg: Sample table例如:样品表

Mark      Math        hw1
David.    Math        hw2
Mark.     Science.    hw1
Mark      Math.       hw2
David.    Science.    hw1
David.    Literature. hw1

Expected results (3 columns)

    Mark | Math    | 2 (because two math homeworks) 
    Mark | Science | 1 home work
    David| Math    | 1 home work
    David| Science | 1 home work
    David| Lit.    | 1 home work 
select name, course, count(*)
  from your_table
 group by name, course

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 COUNT(*)AS发生,php如何捕获每次出现的值 - COUNT(*) AS occurrences, php how do i capture the value of each occurance 如何在MYSQL中使用COUNT和DISTINCT为每个不同的值创建单独的计数? - How can I use COUNT and DISTINCT in MYSQL to create a separate count for each distinct value? 是否可以结合使用“ DISTINCT”和“ COUNT”查询,以便我可以看到每个不同的值出现了多少次? - Is it possible to combine 'DISTINCT' and 'COUNT' queries, so that I can see how many times each distinct value appears? 在MySQL中,如何计算一列中某个值范围的出现次数,而不是另一列中所有唯一值的出现次数? - How can I count the number of occurrences of a range of values in one column, against all unique values in another, in MySQL? 另一列中每个值的列的不同列数 - count of distinct of column for each value in another column 将每个不同值的计数作为SQL中的列返回 - Return a count of each distinct value as a column in SQL 在 mysql 数据库中,您可以将列中某个值的出现次数计算为自动生成的列吗? - In a mysql db, can you count the number of occurrences of a value in a column as an autogenerated column? 如何计算 1 个表 MySql 中两列中不同数据的出现次数 - How do I count occurrences of distinct data in two columns from 1 table MySql MySQL:计算每行不同值的出现次数 - MySQL: Count occurrences of distinct values for each row 用不同的列值计算一列的出现次数? [甲骨文] - Count number of occurrences of one column by a different column value? [Oracle]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM