这是我的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 和SELECT FOUND_ROWS();
但还有另外一种方法吗?
答案 0 :(得分:0)
最简单的方法可能是子查询:
select (select count(*) from Specialization where specialization LIKE '%'+@keyword+'%'`
) as speccnt
注意:如果您正在切换数据库而您正在使用窗口函数等功能,那么您可能会考虑使用Postgres而不是MySQL,因为Postgres支持窗口函数。