: junglerover(灌木丛)
引用Dao 3.60后,
Dim ret As Recordset
Set ret = OpenDatabase("C:\WINDOWS\Desktop\数据库\数据库\test.mdb").OpenRecordset("Select b.B20 From (Select count(*) As B20 From T1 Where (T1.年龄 Between 0 And 20) Group By 车间) As b")
ret.MoveLast
ret.MoveFirst
MsgBox ret.Fields(0).Name
MsgBox ret.Fields(0).Value
测试成功,又学多点东西,谢咯~~~:)
还是没用啊,我是用vb6自带的数据库管理器测试的.
Select b.B20 From (Select count(*) As B20 From T1 Where (T1.年龄 Between 0 And 20) Group By 车间) As b 出现错误..
而Select count(*) As B20 From T1 Where (t1.年龄 Between 0 And 20) Group By 车间
执行正常..
select Table1.车间,
a.Amount as 20以下, b.Amount as 20到30, ....
from TABLE1, (select 车间, Count(*) as Amount from TABLE1 where 当前日期-出生日期 < 20*365 group by 车间) as a,
(select 车间, Count(*) as Amount from TABLE1 where 当前日期-出生日期 >= 20*365 and 当前日期-出生日期 <= 30*365 group by 车间) as b, ......
where TABLE1.车间=a.车间 and TABLE1.车间=b.车间 ......
group by Table1.车间, a.amount, b.amount, ......
order by Table1.车间
设你的表名为T1
select 车间,(select count(*) from t1 as t1_1 where year(now)-year(t1_1.出生日期)<20) as 20岁以下人数,
(seleclt count(*) from t1 as t1_2 where year(now)-year(t1_2.出生日期)>=20 and year(now)-year(t1_2.出生日期)<30) as 20-30岁人数,
(seleclt count(*) from t1 as t1_3 where year(now)-year(t1_3.出生日期)>=30 and year(now)-year(t1_3.出生日期)<40) as 30-40岁人数,
(seleclt count(*) from t1 as t1_4 where 婚否=true) as 已婚,
(seleclt count(*) from t1 as t1_5 where 婚否=false) as 未婚,
(seleclt count(*) from t1 as t1_6 where 学历="研究生") as 研究生,
(seleclt count(*) from t1 as t1_7 where 学历="大学") as 大学,
(seleclt count(*) from t1 as t1_8 where 学历="大专") as 大专,
(seleclt count(*) from t1 as t1_7 where 学历="高中有以下") as 高中及以下
from T1;