数据结构如下:id     name    price      origin       1      数据1    88.00        新浪
2      数据2    18.00        百度
3      数据3    58.00        谷歌
4      数据4    78.00        谷歌
5      数据5    98.00        百度
6      数据6    18.00        百度
7      数据7    28.00        问问
8      数据8    38.00        问问
9      数据9    38.00        新浪
......
1004      数据1004    78.00        谷歌
1005      数据1005    98.00        百度
1006      数据1006    18.00        百度
1007      数据1007    28.00        问问
1008      数据1008    38.00        问问
1009      数据1009    38.00        新浪我要搜索查询的时候得出的结果满足这样的条件:
分页后每页10条,这10条里面的数据 origin 必须是 “新浪,百度,谷歌,问问” 中的,具体几条可以随机;

解决方案 »

  1.   

    第一页:
    select id,name,price,origin from tab where id>0 and origin in ('新浪','百度','谷歌','问问') order by id limit 10;
    记下这一页最后一行的id值,假设为num,
    第二页:
    select id,name,price,origin from tab where id>num and origin in ('新浪','百度','谷歌','问问') order by id limit 10;
    以此类推。
      

  2.   


    不行,得出的都是同一个,比如都是origin=新浪的数据
      

  3.   


    不行,得出的都是同一个,比如都是origin=新浪的数据你的意思是返回的数据一定要包含“新浪,百度,谷歌,问问”这四个?
      

  4.   


    不行,得出的都是同一个,比如都是origin=新浪的数据你的意思是返回的数据一定要包含“新浪,百度,谷歌,问问”这四个?
    是的,只要数据库有这10条数据里面一定要包含这四个,其他6条数据随机显示,或者能做到这每个*2 ,那么就是 这四个*2 -8 条数据,另外两条随意 就更好了
      

  5.   

    有个笨拙的方法,
    select * from (select * from test where origin='百度' order by id limit 0,2) a
    union all
    select * from (select * from test where origin='谷歌' order by id limit 0,2) b
    union all
    select * from (select * from test where origin='新浪' order by id limit 0,2) c
    union all
    select * from (select * from test where origin='问问' order by id limit 0,2) d
    union all 
    select * from (select * from test where originnot in ('百度','谷歌','新浪','问问') order by id limit 0,2) e;