Mysql 常用方法


删除重复数据(根据url删除重复数据)
DELETE FROM `BaiDu_know_new_copy1` WHERE
`user_url` IN (
SELECT x FROM
(
SELECT `user_url` AS x
FROM `BaiDu_know_new_copy1`
GROUP BY `user_url`
HAVING COUNT(`user_url`) > 1
) tmp0
)
AND
`id` NOT IN (
SELECT y FROM
(
SELECT min(`id`) AS y
FROM `BaiDu_know_new_copy1`
GROUP BY `user_url`
HAVING COUNT(`user_url`) > 1
) tmp1
)

更新数据
UPDATE loctek_shop_price SET sku_name=%s ,sku_price=%s,date=%s WHERE id= %s

插入数据
sql = 'insert into baidu_know_url_new(`source`,url) value (%s,%s)'
va = (laiyuan, question_url)
cursor.execute(sql, va)
conn.commit()


一段数据插入一个新表
insert into beauty_copy1 select * from beauty limit 10

删除一段数据

delete from beauty limit 10

删除表中某字段下为空的数据

delete from 表名 where 字段名 is null;

delete from tiktoktext where text=''

替换
update loctek_shop_price set shop_type=REPLACE(shop_type,'站立健康办公','经销商')

查询某个字符串是否在字段里面 Attachment 字段名

select * from EASA_AD where INSTR(Attachment,'0103_Espagnol.pdf')


UPDATE user SET name=LTRIM(name);
去掉右边空格
UPDATE user SET name=RTRIM(name);
去掉全部(左右)空格
UPDATE user SET name=TRIM(name);


posted @ 2022-11-29 18:08  见于初始  阅读(20)  评论(0编辑  收藏  举报