有两个表:(temp和mey)
temp有字段:id,userid,type,units,use, time
1 li 电子 个人 设计 2009-5-25
2 admin 电子 单位 设计 2009-6-1
3 张 纸质 个人 设计 2009-4-25
4 test 电子 单位 施工 2009-5-25
5 test 电子 个人 设计 2009-4-25
mey有字段:mid, userid, fname, ftype,time
1 li B01-001.pdf 复印 2009-5-25
2 li C01-001.pdf 打印 2009-5-25
3 test B01-002.pdf 复印 2009-5-25
4 admin B02-001.pdf 打印 2009-6-1
5 张 B01-004.pdf 复印 2009-4-25
6 admin B02-002.pdf 打印 2009-6-1
7 test B02-002.pdf 扫描 2009-4-25 要查出的结果是:
复印 打印 扫描
个人: 2 1 1
单位: 1 2 0
temp有字段:id,userid,type,units,use, time
1 li 电子 个人 设计 2009-5-25
2 admin 电子 单位 设计 2009-6-1
3 张 纸质 个人 设计 2009-4-25
4 test 电子 单位 施工 2009-5-25
5 test 电子 个人 设计 2009-4-25
mey有字段:mid, userid, fname, ftype,time
1 li B01-001.pdf 复印 2009-5-25
2 li C01-001.pdf 打印 2009-5-25
3 test B01-002.pdf 复印 2009-5-25
4 admin B02-001.pdf 打印 2009-6-1
5 张 B01-004.pdf 复印 2009-4-25
6 admin B02-002.pdf 打印 2009-6-1
7 test B02-002.pdf 扫描 2009-4-25 要查出的结果是:
复印 打印 扫描
个人: 2 1 1
单位: 1 2 0
sum(decode(b.ftype,'复印',1,0)) as 复印,
sum(decode(b.ftype,'打印',1,0)) as 打印,
sum(decode(b.ftype,'扫描',1,0)) as 扫描
from temp a,mey b
where a.id=b.id
group by a.type
sum(decode(b.ftype,'复印',1,0)) as 复印,
sum(decode(b.ftype,'打印',1,0)) as 打印,
sum(decode(b.ftype,'扫描',1,0)) as 扫描
from temp a,mey b
where a.id=b.id
group by a.type
sum(decode(b.ftype,'复印',1,0)) as 复印,
sum(decode(b.ftype,'打印',1,0)) as 打印,
sum(decode(b.ftype,'扫描',1,0)) as 扫描
from temp a,mey b
where a.id=b.id
group by a.type
按时间?ps:上面字段名和数据看串了 -_-##
select a.units,
sum(decode(b.ftype,'复印',1,0)) as 复印,
sum(decode(b.ftype,'打印',1,0)) as 打印,
sum(decode(b.ftype,'扫描',1,0)) as 扫描
from temp a,mey b and a.time =b.time
where a.userid=b.userid
group by a.units
sum(decode(b.FTYPE,'复印',1,0)) 复印,
sum(decode(b.FTYPE,'打印',1,0)) 打印,
sum(decode(b.FTYPE,'扫描',1,0)) 扫描
from templ a,mey b
where a.userid=b.userid
group by a.units