select count(*),type_code,depm_code
from t_info
group by type_code,depm_code
from t_info
group by type_code,depm_code
解决方案 »
- c# 参数化问题? 急
- C#如何调用fortran编译器ivf生成的DLL
- C# 鼠标钩子能否获取到鼠标的移动?
- 急,Object 对象怎样在*.aspx.cs 文件中调用
- 为什么会算错????一个神奇的问题
- 这样的DataGridView如何实现?(分不够的话再加)
- 再来100分,用C#操作Excel添加图表时出错,高手请指点,加上另外一帖的100分,可是200分啦!
- 可否用vs.net编纯c
- C#如何远程连接oracle服务器
- 关于BeginTranscation()和Commit之间的代码
- 运用owc10控件,如何在二维坐标系中添加纵坐标的坐标刻度?
- 请问下面的代码为什么不能得到正确的结果错在什么地方请高手指点一下?
不过用outer join 似乎可以
from t_depm b,t_type c只是没有文章的话查出来是NULL值,可以在前台处理一下就可以了
),0) as count1,c.type_code,b.depm_code
from t_depm b,t_type c
(select nvl(num1,0) as num2,type_code,depm_code from
(select count(*) as num1,type_code,depm_code from t_info) tab11
,t_depm tab12 where tab1.depm_code (+)=tab12.depm_code ) tab21
,t_type tab22 where tab21.type_code(+)=tab22.type_code
group by type_code,depm_code
部门表(t_depm)有一个字段:部门代码
栏目表(t_type)有一个代码:栏目代码
在部门表中多加一个部门名称的字段bmname
在栏目表中多加一个栏目名称的字段lmname
如下:测试通过
select b.bmname,c.lmname,count(*) from t_info a,t_depm b,t_type c where a.depm_code=b.depm_code and a.type_code=c.type_code group by b.bmname,c.lmname,a.type_code,a.depm_code
这样不合要求呀,如果栏目下没文章栏目就不会被查出来,如果部门下没文章部门也不会被查出来
楼主的要求太高了。一条语句想做这么多。去问问邹老大吧。。写存储过程吧。。
id int
,count int
,type_code nvarchar(20)
,depm_code nvarchar(20)
)
然后一条一条插入最后
select * from @table1可以放入一个存储过程当中
from t_depm a cross join t_type b
left join t_info c on c.depm_code=a.depm_code and c.type_code=b.type_code group by a.depm_code,b.Type_code
数据库表中数据为:时间 名称 数据
2000325 name1 1
2001325 name2 2
2002325 name3 3
现在要表现形式为:时间 name1 name2 name3
2000325 1 0 0
2001325 0 2 0
2002325 0 0 3 我是准备绑定DataGraid SQL语句怎么写?
解决方法:declare @s varchar(8000)
set @s=''
select @s=@s+',['+名称+']=sum(case 名称 when '''+名称+''' then 数据 else 0 end)'
from(select distinct 名称 from 表) a
exec('select 时间'+@s+' from 表 group by 时间')
t.type_code,
count(decode(a.info_code, null, 0, 1)) as info_count
from t_info a
right join (
select b.depm_code,
c.type_code
from t_depm b,
t_type c
) t on
a.depm_code = t.depm_code
and a.type_code = t.type_code
group by t.depm_code,t.type_code
;
所以,关联的时候
只能用t_info去右连t_depm和t_type但是,一张表不能同时右连到多张表上(左联是可以的)
所以,我想了个办法:将t_info右连到depm_code和type_code的笛卡尔积上
于是就得到以上的sql语句不过,我不太确定这种方式是否违背前述的原则(一张表不能同时右连到张张表上)试试吧另外,我也挺怀疑这个sql语句的效率---当表depm_code和type_code中数据比较多的时候
我修改了一下上面的sql语句达到了我得要求这个问题困扰了我好久,真的太感谢你们了向回答我问题的同志们致敬!向所有的程序员致敬!