asp数据统计(只要能实现,马上送分)

来源:百度知道 编辑:UC知道 时间:2024/05/31 01:53:27
我有个news表,里面存放的是发布的新闻,包括ID,标题,上传部门,上传时间等字段。我现在想做个统计,能显示出每个部门发布的总量,本年发布数,本月发布数,当日发布数,内容如下:
编号 部门 总数 本年 本月 当日
1 销售部 50 26 4 0
2 办公室 200 162 5 1

请高手指点
感觉lzp4881说的方法不错,也可以理解,但这种用法没有用过.怎么输出呀.我输出变量的值为空呀.

select 上传部门,total=count(上传部门),
nsl=sum(case when year(上传时间)=year(getdate()) then 1 else 0 end),
ysl=sum(case when month(上传时间)=month(getdate()) then 1 else 0 end),
dsl=sum(case when day(上传时间)=day(getdate()) then 1 else 0 end)
from news group by 上传部门

输出用
rs("上传部门")
rs("total")
rs("nsl")
rs("ysl")
rs("dsl")

rs(0)
rs(1)
rs(2)
rs(3)
rs(4)

两种方法:
(conn 为数据库连接对象)

' 统计销售部
sql= "select Count * as num1 from news where 上传部门='销售部' "
conn.execute(sql)
dim xsbnum '销售部发布总数
xsbnum=rs("num1")


sql= "select Count * as num1 from news where 上传部门='销售部' "
set rs=server.createobject("adodb.RecordSet")
rs.open sql,conn,1,1
xsbnum = rs.recordcount

统计其他类似

sql="SELECT SUM(总数+ 本年+ 本月+当日) AS Expr1