sql

1、关于 having:
例1:

在开发时,我们经常会遇到以“累计(count)”或是“累加(sum)”为条件的查询。比如user_num表:
id user num
1 a 3
2 a 4
3 b 5
4 b 7

select user from user_num group by user having count(user)>=2


查询出现过2次的user。  往往初学者会错误地认为在where 语句里直接使用count()算法,很显然这个想法是错误的,count()方法并不能被用在where子句中,
为了解决问题,我们可以在group by子句后面使用HAVING来做条件限制。  
错误做法:select * from user_num where count(user)>=2 group by user;  
正确做法:select * from user_num group by user HAVING count(user)>=2 ;  解释说明:[color=brown]HAVING 与 WHERE 类似,可用来决定选择哪些记录。
HAVING 子句在SELECT语句中指定,显示哪些已用 GROUP BY 子句分组的记录。在GROUP BY组合了记录后, HAVING会显示 GROUP BY 子句分组的任何符合 HAVING
子句的记录。  [/color]

2、 select * from user where nick_name is not null;

3、 select * from user where status in (0,1);
select * from user where id > 100 and (status=0 or status =1);

4、set names 'utf8';

5、
create database zoneidc; drop database [数据库名];
insert into comic_pic (vol_id,file_path,order_num,status) VALUES (4,'haha',0,0),(4,'haha',0,0),(6,'kiki',0,0) //插入多行数据

mysql -u root --default-character-set=utf8 -p db_choose < C:\db_choose.sql
mysqldump -u root -p --default-character-set=utf8 db_choose > C:\db_choose.sql

select * from log_index where date_format(submit_date,'%Y-%m-%d')='2006-01-08'



grant select,insert,update,delete,create,drop on vtdc.employee to joe@10.163.225.87 identified by '123';
grant all privileges on v133_upload.* to v_upload@'%' identified by 'you2top';
grant all privileges on v133_upload.* to v_upload@'%' identified by 'you2top';
flush privileges

revoke all privileges on *.* from v_upload@'%';//删除 用户‘V_UPLOAD’的所有权限
delete from user where user='v_upload' and host='%'//删除用户
flush privileges

mysql -uroot -p
use mysql
select * from user
update user set password=old_password('tobey130982') where user.user = 'zhangyinpei' limit 1;
select * from user
flush privileges

/home/mysql5.0/bin/mysqld_safe --user=mysql &//启动mysql
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值