mysql - 在 mysql 中替换 count(*) OVER ()

标签 mysql sql-server

这是我的 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/

相关文章:

mysql - 只选择不为空的数据

sql - 获取该月的 2 位数字

c# - 代码审查 : CLR RegexSubstring

sql-server - SQL Server 2005内存压力和tempdb写入问题

ruby - 尝试将 Ruby 连接到 SQL 服务器时出现 "Closed connection error"

mysql - SQL:查询得到公司平均工资和部门平均值

mysql - 在sql中显示具有相同id的一行中的值

部分列的 SQL 搜索

mysql - mysql 中的 BIGINT 数据类型在创建表时给出错误

python - 在 Windows 中将 MySQL 与 Python 集成