ITeye博客

做个笔记,根据列A统计列B的数量

wikimo · 2010-02-03 15:07 · 数据库相关 · 数据库 · Markdown

需求描述:

根据列username,对列subject的数量进行统计

 

表的记录集:

+----+---------+----------+

| id | subject | username |

+----+---------+----------+

|  1 | 记录一  | admin    |

|  2 | 记录二  | admin    |

|  3 | 记录三  | admin    |

|  4 | 记录四  | test1    |

|  5 | 记录五  | test2    |

|  6 | 记录六  | test2    |

+----+---------+----------+

 

需要的结果:

+----------+-----+

| username | num |

+----------+-----+

| admin    |   3 |

| test1    |   1 |

| test2    |   2 |

+----------+-----+

 

 

SQL:select username,count(subject) as num from 表名 group by username

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。