1. 程式人生 > >mysql 正則匹配內容查詢、拼接sql語句

mysql 正則匹配內容查詢、拼接sql語句

-- -- 廣告評論刪除

-- SELECT count(ID) FROM t_article_comment WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]';
-- 
-- 
-- SELECT * FROM t_article_comment WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]';
-- 
-- 
-- SELECT count(tc.ID) FROM t_article_comment as tc LEFT JOIN t_app_user as tu on tu.ID = tc.CREATOR 
-- WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]';
-- 
-- 
-- SELECT tc.*,tu.ID as userID,tu.NICK_NAME,concat('UPDATE t_app_user SET `status`=2 where ID= "',tu.ID,'";') as sqltxt FROM t_article_comment as tc LEFT JOIN t_app_user as tu on tu.ID = tc.CREATOR 
-- WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]';


-- SELECT * FROM t_article_comment WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]';
-- 
-- DELETE FROM t_article_comment WHERE CONTENT REGEXP "[0-9]{8}" and CONTENT REGEXP '[^0-9.]'

-- 恢復評論數

-- update t_article set COMMENT_COUNT = where 

-- select ID, COMMENT_COUNT from t_article as t LEFT JOIN t_article_comment as tc on tc.ARTICLE_ID = t.ID;

select ARTICLE_ID,count(ID),CONCAT('update t_article set COMMENT_COUNT = ',count(ID),' where ID = "',ARTICLE_ID,'";') as sqlTxt from t_article_comment GROUP BY ARTICLE_ID;