继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

MYSQL随笔

慕瓜5202747
关注TA
已关注
手记 3
粉丝 3
获赞 47

1.mysql查询重复记录方法

select * from table1
where t_id in (select t_id from table1 group by t_id having count(t_id) > 1);

select * from table1
where t_id in (select t_id from table1 group by t_id having count(t_id) > 1);

2.mysql新建用户及分配数据库权限

CREATE USER admin123 IDENTIFIED BY 'pwd';
GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'pwd';

3.mysql将一张表部分字段数据更新到另一张关联表

UPDATE  tablename1 as  B, tablename2 as C
SET B.gender=C.gender
WHERE C.id=B.id

4.mysql删除重复数据,只保留一行

  • 用户表members member_name存在重复值, 删除重复值,只保留id最大一行
DELETE FROM members WHERE member_name IN 
	( SELECT t.member_name FROM ( SELECT member_name FROM members GROUP BY member_name HAVING count(1) > 1 ) t )
		AND member_id NOT IN (SELECT dt.mindeptno FROM ( SELECT max(member_id) AS mindeptno FROM members GROUP BY member_name HAVING count(1) > 1 ) dt)
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP