以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何用SQL生成这样的统计表?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=31437)

--  作者:lihe60
--  发布时间:2013/4/15 12:12:00
--  如何用SQL生成这样的统计表?

如何用SQL生成这样的统计表?

要求:需用SQL语句生成临时表。

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目15.table


--  作者:Bin
--  发布时间:2013/4/15 12:17:00
--  
不一定需要用SQL来生成.
--  作者:lihe60
--  发布时间:2013/4/15 12:20:00
--  

可能有其他的方法,现在需要SQL语句生成。


--  作者:Bin
--  发布时间:2013/4/15 12:21:00
--  
用其他方法会简便很多也比较适合.  
--  作者:Bin
--  发布时间:2013/4/15 12:23:00
--  
如果单独统计某一个班的还好办一点.你要统计所有班的.
恐怕很有经验的程序员 也写不出这SQL语句来.

--  作者:lihe60
--  发布时间:2013/4/15 12:48:00
--  

http://soft.zdnet.com.cn/software_zone/2009/1202/1532996.shtml

 

如何写成狐表可执行语句。

 

这是列合并,如果是列求和,又如何写语句?

[此贴子已经被作者于2013-4-15 12:49:05编辑过]

--  作者:lihe60
--  发布时间:2013/4/15 13:11:00
--  

select a.xh,(case when b.th1 is null then \'\' else b.th1 end) as th1,(case when c.th2 is null then \'\' else c.th2 end) as th2,(case when d.th3 is null then \'\' else d.th3 end) as th3 from (select xh from {t_table} group by xh) a left join (select xh,value as th1 from {t_table} where th=\'1\') b on a.xh=b.xh left join (select xh,value as th2 from {t_table} where th=\'2\') c on a.xh=c.xh left join (select xh,value as th3 from {t_table} where th=\'3\') d on a.xh=d.xh

 

照葫芦画瓢。

代码好长,也不执行。


--  作者:Bin
--  发布时间:2013/4/15 13:16:00
--  
你非要用SQL语句的话.
select [班级编号], count(case when [性别]=\'男\' then 1 end) as 男,
 count(case when [性别]=\'女\' then 1 end) as 女 
 from (select * from 一班  union all select * from 二班) as tb2  group by [班级编号]


--  作者:don
--  发布时间:2013/4/15 13:32:00
--  
...
[此贴子已经被作者于2013-4-15 17:51:43编辑过]

--  作者:lihe60
--  发布时间:2013/4/15 13:34:00
--  
以下是引用Bin在2013-4-15 13:16:00的发言:
你非要用SQL语句的话.
select [班级编号], count(case when [性别]=\'男\' then 1 end) as 男,
 count(case when [性别]=\'女\' then 1 end) as 女 
 from (select * from 一班  union all select * from 二班) as tb2  group by [班级编号]

Select 班级编号,count(Case when 性别=\'男\' then 1 end) as 男, count(case when 性别=\'女\' then 1 end) as 女  from (select * from {一班}  union all select * from {二班}) as tb2  group by 班级编号

这个代码不执行的。