永发信息网

SQL语句查询数据条数

答案:4  悬赏:0  手机版
解决时间 2021-02-26 14:07
  • 提问者网友:雪舞兮
  • 2021-02-26 08:32
比如说我现在有一个网站一个月的点击数据,每个来访者的点击时间都会被记录,我现在想要列出一个表,显示日期和点击数,但是以下语句只能查出一天,比如11月1日
select count (*) from 表名 where opendate=‘2013年11月1日’
我想要整个月的日期和时间全部列出来怎么一次性查啊,不要查30次
最佳答案
  • 五星知识达人网友:纵马山川剑自提
  • 2021-02-26 09:30
查询全部
select opendate,count (*) from 表名 group by opendate查询某月
select opendate,count (*) from 表名 where opendate like '2013年11月%' group by opendate
全部回答
  • 1楼网友:神鬼未生
  • 2021-02-26 12:40
class classid classname product classid proname num select top 10 c.classid ,c.classname,sum(p.num) from class c,product p where p.classid=c.classid group by c.classid order by sum(p.num) desc 有的不能用top。,不同数据库软件查询好像有细微的差别。
  • 2楼网友:玩家
  • 2021-02-26 11:53
我相信你会用group by,而遇到的问题是要把datetime转为date,去掉时间对吧。如果是db2,直接对日期如int(),如int(2013-11-04 11:00) 就转出 20131104。sql server需要你自己去实现这个int函数,很简单。 select a.opendate_int,count(1) click_count from ( select *,int(opendate) opendate_int from table where int(opendate)/100=201310) a group by a.opendate_int order by 1
  • 3楼网友:梦中风几里
  • 2021-02-26 10:28
select s.d,sum(s.c) from (select t.opendate,to_char(t.opendate,'yyyymmdd') d, count(to_char(t.opendate,'yyyymmdd')) c from 表名t where t.opendate>= to_date('20131001', 'yyyymmdd') and t.opendate<= to_date('20131031', 'yyyymmdd') group by t.opendate) s group by s.d order by s.d 完整的sql语句 , 应该可以直接执行
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯