日期:2014-05-18  浏览次数:21173 次

求正则替换sql语句为select count(*) from
求替换SQL的办法
select t0.*
(select count(*) from news where creatorid=t0.userid) pCount
from user t0
left join
(select * from xxxxx) t1
on t0.userid=t1.id
where t0.xx=xx
需要查询出该SQL的count有多少个
以前我是在这句sql外面包了句select count(*) from (上面那句sql)
但是发现MYSQL在大数据量下的嵌套查询的速度简直是无法忍受
那么我就想试着用正则表达式替换其中select.........from这一段为select count(*) from

我想从select t0.*到from user t0替换为select count(*) from
可是不知正则该如何实现我的需求,请高手帮个忙,谢谢

------解决方案--------------------
哦,明白你的意思。。

C# code
Regex.Replace(str,@"^select (?:(?!select|from)[\s\S])*(\(select (?:(?!from)[\s\S])* from [^\)]*\)(?:(?!select|from)[^\(])*)*from","select count(*) from");