ASP+SQL数据汇总输出

yzdjody 2015-01-09 02:25:20

要从表一得到下面三张表


求大神指导。不会弄啊。
...全文
382 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
brotherq 2015-02-24
  • 打赏
  • 举报
回复
以上有点小错,更正如下: 部门应该是固定的,简单一点,假设子公司A只有“工”、“在”、”一“、”中“四个部门。 先得到子公司A的表一: sql="select 公司,部门,流水号,请购单号,姓名,数量,单价,品名,小计,sum(case 部门 when '工' then 小计 else 0 end) as 工总计," sql=sql&"sum(case 部门 when '在' then 小计 else 0 end) as 在总计,sum(case 部门 when '一' then 小计 else 0 end) as 一总计," sql=sql&"sum(case 部门 when '中' then 小计 else 0 end) as 中总计 " sql=sql&"from 表1 Where 公司='A' order by 部门" rs.open sql,conn,1,3 if not rs.eof then i=1 depart="" do while not rs.eof depart=rs("部门) if i=1 then str=str& "<tr><td rowspan=""{$部门流水数}"">"&rs("部门)&"</td><td>"&rs("流水号)"&"</td><td>"&...&"</td>" str=str&"<td rowspan=""{$部门流水数}"">{$str1}"&"</td></tr>" else str=str& "<tr><td>"&rs("流水号")"&"</td><td>"&...&"</td></tr>" end if rs.movenext if rs("部门)"<>depart then str1=depart&"总计" str=replace(str,{$str1}, rs(str1)) str=replace(str,{$部门流水数},i) i=1 else i=i+1 end if loop response.write str 子公司B的表如此类推。 自己再想想把公司列也加进去,再判断一个j就行了。
brotherq 2015-02-24
  • 打赏
  • 举报
回复
部门应该是固定的,简单一点,假设子公司A只有“工”、“在”、”一“、”中“四个部门。 先得到子公司A的表一: sql="select 公司,部门,流水号,请购单号,姓名,数量,单价,品名,小计,sum(case 部门 when '工' then 小计 else 0 end) as 工总计," sql=sql&"sum(case 部门 when '在' then 小计 else 0 end) as 在总计,sum(case 部门 when '一' then 小计 else 0 end) as 一总计," sql=sql&"sum(case 部门 when '中' then 小计 else 0 end) as 中总计 " sql=sql&"from 表1 Where 公司='A' order by 部门" rs.open sql,conn,1,3 if not rs.eof then i=1 depart="" do while not rs.eof depart=rs("部门) if i=1 then str=str& "<tr><td rowspan=""{$部门流水数}"">"&rs("部门)&"</td><td>"&rs("流水号)"&"</td><td>"&...&"</td>" str1=rs("部门")&"总计" str=str&"<td rowspan=""{$部门流水数}"">"&rs(str1)&"</td></tr>" else str=str& "<tr><td>"&rs("流水号")"&"</td><td>"&...&"</td></tr>" end if rs.movenext if rs("部门)"<>depart then str=replace(str,{$部门流水数},i) i=1 else i=i+1 end if loop response.write str 子公司B的表如此类推。 自己再想想把公司列也加进去,再判断一个j就行了。
xyy7309 2015-02-15
  • 打赏
  • 举报
回复
循环嵌套,如: rs.open "select * from 表1 order by 子公司",conn,1,3 rs1.open "select * from 表1 WHERE 子公司=rs("子公司") order by 子公司,部门",conn,1,3
zhh828 2015-01-30
  • 打赏
  • 举报
回复
好高级的样子。
wtg321 2015-01-30
  • 打赏
  • 举报
回复
EXCEL的话可以用用数据透视表做一下
xiaoliuvv 2015-01-27
  • 打赏
  • 举报
回复
tmp1="" rs.open "select * from 表1 order by 子公司,部门",conn,1,3 if not rs.eof then do while not rs.eof response.write "<tr>" if rs("子公司")<> tmp1 and tmp1<>"" then 子公司数量=conn.execute("select count(*) from 表1 where 子公司='"&rs("子公司")&"'")(0) response.write "<td rowspan="&子公司数量&">"&rs("子公司")&"</td>" tmp1 = rs("子公司") end if '以上是输出子公司的思路,部门和总计那两列同理,再次衔套就行 response.write "<td>"&rs("流水号")&"</td>" response.write "<td>"&rs("请购单号")&"</td> 。。。。。。 。。。。。。 loop end if 看明白了吗,直接输出就行,就是单元格组合的问题,大概写的,有错误自己判断吧
Go 旅城通票 2015-01-23
  • 打赏
  • 举报
回复
order by 子公司,部门 按照上面的排序,自己记录下子公司和部门的值,进行统计和数据行的合并输出就好。。
rings2000 2015-01-23
  • 打赏
  • 举报
回复
在EXCEL中不太好搞呀
yzdjody 2015-01-22
  • 打赏
  • 举报
回复
求大神指导,大神在哪里啊
yzdjody 2015-01-10
  • 打赏
  • 举报
回复
不好合并吧。
rokerker 2015-01-09
  • 打赏
  • 举报
回复
看了下数据,是从总表中按照子公司、部门进行group by 合计吧。 可是这个输出格式好像又不大合适,明显的还有明细数据存在,比如流水号、姓名、单品这些。 单看你给出的效果图,直接把所有的数据查询出来(不group by),然后按照子公司、部门来逐行的处理,进行单元格合并就能达到要求

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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