分组查找ACCESS数据库,每组随机取N条记录的例子

分组查找ACCESS数据库,每组随机取N条记录并按照id排序

 

ACCESS数据库结构为:表名ff。字段有:id(自动编号),ff(文本),aa(文本),bb(文本),cc(文本)

以下是ACCESS导出的文本文件:

1,"aa","a1","a1","a1"
2,"aa","a2","a2","a2"
3,"aa","a3","a3","a3"
4,"aa","a1","a1","a1"
5,"aa","a2","a2","a2"
6,"aa","a3","a3","a3"
7,"bb","b4","b1","b1"
8,"bb","b5","b2","b2"
9,"bb","b6","b3","b3"
10,"bb","b1","b1","b1"
11,"bb","b2","b2","b2"
12,"bb","b3","b3","b3"
13,"bb","b4","b1","b1"
14,"bb","b5","b2","b2"
15,"bb","b6","b3","b3"

 

SQL语句如下:

select * from (select top 2 * from ff where ff="aa" order by rnd(id))
 UNION ALL (select top 2 * from ff where ff="bb" order by rnd(id))
ORDER BY id;

每组要出几条记录只要把每组top后的数据改成几就行了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值