这是我的 SQL 服务器查询
` Select top 8
count(id) OVER () as speccount,
(SELECT count(*) From Profile_Master pm WHERE CONCAT(pm.fname , pm.lname) LIKE '%'+@keyword+'%' and
(select Top 1 city from DAddress_Master where profileid=pm.id)=@city) as drcount,
(SELECT count(*) From DAddress_Master dam WHERE dam.city=@city and dam.clinicname LIKE '%'+@keyword+'%') as cliniccount,
specialization AS name,
id as id,
'Specialization' as type,
'' as drspec
From Specialization_Master
Where specialization LIKE '%'+@keyword+'%'`
实际上是我整个查询的一部分。现在我必须将这个查询转换成 mysql,这没什么大不了的,但是有人能告诉我 mysql 中 count(*) OVER () 的替代品吗?
我遇到了这个功能。
SELECT SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS();
但是还有别的办法吗??
最佳答案
最简单的方法可能是子查询:
select (select count(*) from Specialization where specialization LIKE '%'+@keyword+'%'`
) as speccnt
注意:如果您正在切换数据库并且正在使用窗口函数等功能,您可能会考虑使用 Postgres 而不是 MySQL,因为 Postgres 支持窗口函数。
关于mysql - 在 mysql 中替换 count(*) OVER (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36498664/