VB6 ACCESS里一个超级复杂的难题,望各位大神解答,谢谢(在线等答复)
VB6 ACCESS里面 表名是表名1格式如下
日期 奖金 迟到扣钱
20090105 500 50
20120101 400 100
20120107 300 150
20120113 300 150
20120114 400 100
..........................
如何查询 奖金和迟到扣钱 里 出现次数最多的一个数字,二行同时分别查询,分别显示在TEXT1和text2里面(要精确查询,同时出现2个或2个以上全部显示在TEXT里面)
请问怎么实现这个查询,该使用什么语句???、很困扰 为什么要同时查,分二次不行么? 没看明白lz的意图,不知道是否是这样:
select Top 1 * FROM (select count(*) AS mCount FRON 表1 Group BY 迟到扣钱 ORDER BY mCount DESC)
select Top 1 * FROM (select count(*) AS mCount,迟到扣钱 FRON 表1 Group BY 迟到扣钱 ORDER BY mCount DESC)
非常感谢回答,是这样的 我补充下 在指定时间段(也就是按日期查询比如20120101到20120117)里查询奖金和迟到扣钱 里 出现次数最多的一个数字,分别显示在TEXT1和text2里面(要精确查询,同时出现2个或2个以上全部显示在TEXT里面)
查询指定时间段的已经搞定 剩下的没有思路 不知道用什么语句
strquery = "select * from 表名1 where 日期 >= " & Trim(Text9.Text) & " and 日期 <= " & Trim(Text10.Text) & ""
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strquery
Adodc1.Refresh --创建测试表
create table t_test_tb as select * from
(
select 20090105 as fdate, 500 as Bonus, 50 as Deduct from dual
union
select 20120101, 400, 100 from dual
union
select 20120107, 300, 150 from dual
union
select 20120113, 300, 150 from dual
union
select 20120114, 400, 100 from dual
)
--奖金出现最多次数
select *
from (select bonus, count(1) as counted
from t_test_tb
group by bonus
having count(1) > 1)
where counted = (select max(counted)
from (select bonus, count(1) as counted
from t_test_tb
group by bonus
having count(1) > 1)
)
--结果
BONUS COUNTED
---------- ----------
400 2
300 2
--罚金出现最多次数
select *
from (select Deduct, count(1) as counted
from t_test_tb
group by Deduct
having count(1) > 1)
where counted = (select max(counted)
from (select Deduct, count(1) as counted
from t_test_tb
group by Deduct
having count(1) > 1))
--结果
DEDUCT COUNTED
---------- ----------
100 2
150 2
补充:VB , 数据库(包含打印,安装,报表)