首页 » ASP代码 » 关于Group By的用法,实现分组统计

关于Group By的用法,实现分组统计

以前始终不知道这个SQL语句啥意思,太懒了没仔细看,当自己遇到麻烦了才去了解group by是什么作用 。
例子:其中一个日记表,假设只有两个字段,一个日期,一个标题。日期是可重复的,也就是说一天可以写N条日记。
我现在要统计某天的日记,当然很简单

select count(*) from 日记表 where 发表日期="2010-4-8" 

如果我要依次列出,日期,当天发贴数呢。没出现的日期不要列,有的可能会想到一个循环,把所有时间来where。
这样很费劲的,而且会把不该列的日期列出来。其实一条语句就可以解决。

SELECT 发表日期,count(*) FROM 日记表 GROUP BY 发表日期 Order By 发表日期 ASC"

, ,

转发到新浪微博 转发到新浪微博

目前这篇文章有4条评论(Rss)

  1. dizi download | #1
    05/16/2012 at 13:01

    hey admin thanks for wonderful and straightforward understandable publish i beloved your website internet site seriously much bookmarked also

  2. zinc | #2
    05/16/2012 at 14:51

    Another very entertaining post. Ive been reading through some of your posts and finally decided to drop a comment on this one. Please feel free to visit my site Doppler

  3. http://www.gpsmoto.org/ | #3
    05/16/2012 at 19:23

    But wanna say that this is invaluable , Thanks for taking your time to write this. “We do not attract what we want, But what we are.” by James Allen.

  4. zinc | #4
    05/16/2012 at 21:04

    Another very entertaining post. Ive been reading through some of your posts and finally decided to drop a comment on this one. Please feel free to visit my site click here

我要评论