SELECT count(`id`) as ceshi ,count(`ids`) as cishi FROM `think_ceshi` having ceshi >100 and cishi < 100 order by ceshi desc
注意问题:having不能加在order by后面,但是可以在group by 后面
今天在执行一条mysql语句的时候,左思不得其解,sql如下:
select a.id,(select sum(`id`) from ceshi_b where id=a.id)abc from ceshi_a a where id <100 having abc < 1
然后就让人蛋疼了,一大批数据没显示出来,闹了半天,abc输出的是null,然后就开始搜索转变的方式。
最终找到了
如何解决远程连接mysql出现Can’t connect to MySQL server on (111 “Connection refused”)的问题
在Mysql的远程连接,当配置完账号权限后,却发现远程连接的时候出现
Can't connect to MySQL server on (111 "Connection refused")
的问题,经过排查解决了这个问题。
设置随机出来30条
"SELECT ceshi FROM `ceshi_table` ORDER BY RAND() LIMIT 30
也可以根据条件随机出来10条(条数自己定义)
"SELECT ceshi FROM `ceshi_table` where `id` >10 and `id`<100 ORDER BY RAND() LIMIT 10
MySQL可以通过field()函数自定义排序,格式:field(value,str1,str2,str3,str4),value与str1、str2、str3、str4比较,返回1、2、3、4,如遇到null或者不在列表中的数据则返回0
SQL:select * from table where id IN (3,6,9,1,2,5,8,7)
这样的情况取出来后,其实,id还是按1,2,3,
删除表中多余的重复记录,重复记录是根据单个字段(id)来判断,只留有rowid最小的记录
//删除用户 根据用户名,并且不包括最小ID
delete from users where username in (
--根据用户名称排序,大于1
select username from users group by username having count(username) &
今天打开后台管理的时候,突然有一个登录记录的功能不能用了,然后就去查了下问题,在打开mysql的时候那个记录日记表think_log的时候,提示:
Table './yuyue/think_log' is marked as crashed and should be repaired
提示该表损坏,必须修复。
解决方法:
一个是利用Discuz的Tools急诊箱进行修复。
一个是用phpmya