mysql not in用法
select * from zan where uid not in(select uid from zan where zhongjiang !=0) group by uid order by rand() limit 40
不过这个执行效率比较低,正在找更好用的方法
我觉得还是不如两条语句分开来写,先查出所有的uid,然后再用not in 这样查询速度快很多
$sql="select uid from zan where zhongjiang !='0'";
$res=$dbs->query($sql);
$uid='';
while($o=$dbs->fetch_object($res)){
$uid.=$o->uid.',';
}
$uid=substr($uid,0,strlen($uid)-1);
$sql="select * from zan where uid not in($uid) group by uid order by rand() limit 40";
$res=$dbs->query($sql);
$arr=array();
while($o=$dbs->fetch_object($res)){
$arr[]=$o;
}
mysql not in用法的更多相关文章
- mysql的DATE_FORMAT用法
DATE_FORMAT(date,format) date 参数是合法的日期.format 规定日期/时间的输出格式. mysql的DATE_FORMAT用法 %a 缩写星期名 %b 缩写月名 %c ...
- mysql group by 用法解析(详细)
在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的 ...
- (转载)mysql group by 用法解析(详细)
(转载)http://blog.tianya.cn/blogger/post_read.asp?BlogID=4221189&PostID=47881614 mysql distinct 去重 ...
- (转载)mysql中limit用法
(转载)http://hi.baidu.com/sppeivan/item/e45179375d6778c62f8ec221 mysql中limit用法 使用查询语句的时候,经常要返回前几条或者中 ...
- Mysql临时表的用法 - 51CTO.COM
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- mysql进阶(二十八)MySQL GRANT REVOKE用法
mysql进阶(二十八)MySQL GRANT REVOKE用法 MySQL的权限系统围绕着两个概念: 认证->确定用户是否允许连接数据库服务器: 授权->确定用户是否拥有足够的权限执 ...
- mysql的if用法解决同一张数据表里面两个字段是否相等统计数据量。
MySQL的使用用法如下所示:格式:if(Condition,A,B)意义:当Condition为true时,返回A:当Condition为false时,返回B.作用:作为条件语句使用.mysql的i ...
- MySQL Execution Plan--EXPLAIN用法
MySQL Explain新用法: --使用EXPLAIN来查看语句的最终执行计划 语法:EXPLAIN [EXTENDED] SELECT select_options --在MYSQL .7版本后 ...
- MySQL replace into 用法
讨人喜欢的 MySQL replace into 用法(insert into 的增强版) 在向表中插入数据的时候,经常遇到这样的情况:1. 首先判断数据是否存在: 2. 如果不存在,则插入:3.如果 ...
- MySQL replace into 用法(insert into 的增强版)
转 http://blog.csdn.net/risingsun001/article/details/38977797 MySQL replace into 用法(insert into 的增强版) ...
随机推荐
- Android使用ShowcaseView加入半透明操作提示图片的方法
http://beeder.me/2014/11/11/how-to-add-a-semi-transparent-demo-screen-using-showcaseview/ 这篇文章具体介绍了如 ...
- js控制textarea输入字符串的个数,鼠标按下抬起推断输入字符数
[Html代码] <table> <tr> <td width="150">短信内容:</td> <td> <te ...
- Keyboard input
Keyboard input Python provides a build-in function called raw_input (in version 2.x) that gets input ...
- BZOJ 1588 平衡树 模板题
Treap: //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; int si ...
- c# static 常量
1 关键字 static 修饰 类 字段 属性 方法 ,标记static的就不用创建类的实例调用了,直接通过类名点出来 2 用于变量前,表示每次重新使用该变量所在的方法,类或者自定义的类时,变量的值 ...
- 976 B. Lara Croft and the New Game
You might have heard about the next game in Lara Croft series coming out this year. You also might h ...
- Unified BeginFrame scheduling for Chrome
Unified BeginFrame scheduling for Chrome http://goo.gl/D1Qxrr Status: http://crbug.com/401331 and ht ...
- caffe(9) caffe例子
为了程序的简洁,在caffe中是不带练习数据的,因此需要自己去下载.但在caffe根目录下的data文件夹里,作者已经为我们编写好了下载数据的脚本文件,我们只需要联网,运行这些脚本文件就行了. 注意: ...
- mysql更改密码与远程管理
set password = ': #在当前用户下更改密码 grant all privileges on *.* to root@"%" identified by " ...
- 【cdoj 1544】当咸鱼也要按照基本法
[题目链接]:http://acm.uestc.edu.cn/#/problem/show/1544 [题意] [题解] 容斥原理题; 1..(2^m)-1枚举 设k为其二进制形式中1的个数; k为奇 ...