Home > Backend Development > PHP Tutorial > mysql查询有关问题-80分-包括前面的分

mysql查询有关问题-80分-包括前面的分

WBOY
Release: 2016-06-13 12:24:09
Original
802 people have browsed it

mysql查询问题---80分-包括前面的分

本帖最后由 amu1433 于 2015-07-13 12:16:30 编辑 前面发的这个有问题 http://bbs.csdn.net/topics/391071156 重新更正下...

id             name            nid
1               名字1             3
3               名字1             3
4               名字1             3
5               名字1             3

1               名字1             4
2               名字1             4
5               名字1             4

1               名字1             5
3               名字1             5
5               名字1             5


nid 等于3的记录集为1,2,3,4,5
nid 等于4的记录集为1,2,5
nid 等于5的记录集为1,3,5


怎么获取者三个记录集的共同的id
就是ID=1  跟ID=5
------解决思路----------------------
执行
select uid, group_concat(id) as id from tbl_name group by uid
Copy after login

并读取成
$r[3] = explode(',', '1,2,3,4,5');<br />$r[4] = explode(',', '1,2,5');<br />$r[5] = explode(',', '1,3,5');<br /><br />$t = call_user_func_array('array_intersect', $r);<br />print_r($t);
Copy after login
Array<br />(<br />    [0] => 1<br />    [4] => 5<br />)<br /><br />
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template