sql 语句的写法

虽不简单 2013-01-21 08:49:08
有一个user表,有许多类型的用户信息(type 有1到9个类型表示9个类型的用户),其中有个inputtime字段,记录录入的时间,
那么我有一个这样的需求,想在前台提供一个时间(如 2012-12)取出这个月的不同类型的数量.那么这个语句该咋写呢?程序用的spring.
谢谢大家!
...全文
272 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
2013-01-22
  • 打赏
  • 举报
回复
请问lz是什么数据库 我写的是mysql的。。。语法应该没问题
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
引用 8 楼 zhang527 的回复:
SELECT TRUNC(A.INPUTTYPE),TO_CHAR(A.TYPE) as TYPE,count(*) as count FROM TABLE A GROUP BY to_char(A.TYPE),TRUNC(A.CINPUTTIME) ;
神马意思?
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
引用 7 楼 rollet 的回复:
SQL code ? 1 select sum(if(type=1,1,0))as newsgnum,sum(if(type=2,1,0))as newjlnum,sum(if(type=3,1,0))as newjsnum,sum(if(type=4,1,0))as newjcnum,sum(if(type=5,1,0))as newkcnum,sum(if(type=6,……
if附近有错误呢!
zhang527 2013-01-22
  • 打赏
  • 举报
回复
SELECT TRUNC(A.INPUTTYPE),TO_CHAR(A.TYPE) as TYPE,count(*) as count FROM TABLE A GROUP BY to_char(A.TYPE),TRUNC(A.CINPUTTIME) ;
2013-01-22
  • 打赏
  • 举报
回复
select sum(if(type=1,1,0))as newsgnum,sum(if(type=2,1,0))as newjlnum,sum(if(type=3,1,0))as newjsnum,sum(if(type=4,1,0))as newjcnum,sum(if(type=5,1,0))as newkcnum,sum(if(type=6,1,0))as newzxnum,sum(if(type=7,1,0))as newzbnum,sum(if(type=8,1,0))as newclnum,sum(if(type=9,1,0))as newbxnum from userg where time>'2012-01'
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
select  *  from 
(select count(*) as newsgnum from userg where time > '2012-01' and type='1') sg
,
(select count(*) as newjlnum from userg where time > '2012-01' and type='2') jl
,
(select count(*) as newjsnum from userg where time > '2012-01' and type='3') js
,
(select count(*) as newjcnum from userg where time > '2012-01' and type='4') jc
,
(select count(*) as newkcnum from userg where time > '2012-01' and type='5') kc
,
(select count(*) as newzxnum from userg where time > '2012-01' and type='6') zx
,
(select count(*) as newzbnum from userg where time > '2012-01' and type='7') zb
,
(select count(*) as newclnum from userg where time > '2012-01' and type='8') cl
,
(select count(*) as newbxnum from userg where time > '2012-01' and type='9') bx


这是我写的一个语句。
能得到这样的结果
我想要的是能穿个时间实时的查处这些数字来。。
谢谢!
yzsunlight 2013-01-22
  • 打赏
  • 举报
回复
SELECT type,COUNT(*) FROM testTb GROUP BY type 判断时间方法每个数据库函数不一样
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
引用 14 楼 rollet 的回复:
你还是用这个吧 按顺序依次是type 1 - 9的值 需要你后台去联系上 SQL code ? 1 SELECT type,COUNT(*) FROM userg GROUP BY type ORDER BY type ASC;
给力阿!这个可以,我写完程序给你分哈!!
a12939026 2013-01-22
  • 打赏
  • 举报
回复
ORACLE 写的 写了3行 select sum(decode(type,1,cc,0)) as sg, select sum(decode(type,2,cc,0)) as jl, select sum(decode(type,3,cc,0)) as js from (select type, count(*) as cc from userg where time > '2012-01' group by type) 大致这样 比那个的效率应该要高一点,希望能帮到你
2013-01-22
  • 打赏
  • 举报
回复
你还是用这个吧 按顺序依次是type 1 - 9的值 需要你后台去联系上
SELECT type,COUNT(*) FROM userg GROUP BY type ORDER BY type ASC;
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
有咩有人知道如何写这个语句阿?
虽不简单 2013-01-22
  • 打赏
  • 举报
回复
引用 11 楼 rollet 的回复:
请问lz是什么数据库 我写的是mysql的。。。语法应该没问题
哦,不好意思,该早告诉你的 是sqlserver 2005。
简易人 2013-01-21
  • 打赏
  • 举报
回复
引用 楼主 zhq2012 的回复:
有一个user表,有许多类型的用户信息(type 有1到9个类型表示9个类型的用户),其中有个inputtime字段,记录录入的时间, 那么我有一个这样的需求,想在前台提供一个时间(如 2012-12)取出这个月的不同类型的数量.那么这个语句该咋写呢?程序用的spring. 谢谢大家! ……
chierhuo 2013-01-21
  • 打赏
  • 举报
回复
不一样的数据库用的时间函数有区别,楼上的几位已经解决了语句问题
清风de家 2013-01-21
  • 打赏
  • 举报
回复
select count(*) from user wherer inputtime = to_date('2012-12','yyyy-mm') group by type 时间类型的字段需要转换
桃园闲人 2013-01-21
  • 打赏
  • 举报
回复

select count(*) from user where inputtime = '2012-12' group by type;

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧