数据表结构是这样子
表一(action):
id name
1 吃饭
2 说话
3 唱歌
表二(log):
id action_id status
1 1 0
2 1 1
3 1 1
4 1 1
5 2 1
5 2 1
7 2 1
8 3 0
9 3 1
求出表一(id)对应表二中(action_id)存在数据总和,以及status=1的数量等于总和的action数据出来:
比如:
action表里的第一条id为1的数据,在log表里的记录总数为4条,但是stauts=1的记录却只有3条,那么过滤掉不取;
然后我们来看action表里第二条id为2的数据,在log表里的记录总数为3,status为1的记录也有3条,那么就把action表里id为2的数据取出来,依次类推...
求一条sql语句或者能做到这样效果的方法
可以实现分页效果,每次取出n条action表满足条件的数据
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
select a.* from action a , log l where a.id=l.action_id and l.status=1 limit 0, 10