【问题标题】:substitute of count(*) OVER () in mysql在mysql中代替count(*) OVER()
【发布时间】:2016-07-29 15:53:14
【问题描述】:

这是我的 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,这没什么大不了的,但是有人可以告诉 count(*) OVER () 在 mysql 中的替代品吗?

我遇到了这个函数。

选择 SQL_CALC_FOUND_ROWS 和 SELECT FOUND_ROWS();

但是还有其他方法吗??

【问题讨论】:

    标签: mysql sql-server


    【解决方案1】:

    最简单的方法可能是子查询:

    select (select count(*) from Specialization where specialization LIKE '%'+@keyword+'%'`
           ) as speccnt
    

    注意:如果您正在切换数据库并且正在使用诸如窗口函数之类的功能,您可能会考虑使用 Postgres 而不是 MySQL,因为 Postgres 支持窗口函数。

    【讨论】:

      猜你喜欢
      • 2020-12-08
      • 2019-02-08
      • 2022-12-02
      • 2021-07-04
      • 2021-12-15
      • 2016-01-14
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多