mysql - 如何创建函数过滤 PostgreSQL 到 MySQL?
问题描述
如何创建函数过滤PostgreSQL 到 MySQL?
我尝试如下,但失败了:
select
CASE WHEN statusstorie = false and statusTwentyFive = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "25%",
CASE WHEN statusstorie = false and statusFifty = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "50%",
CASE WHEN statusstorie = false and statusSeventyFive = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "75%",
CASE WHEN statusstorie = false and statusOneHundred = true and category not in ('goals') and space = 'personal' THEN count(*) ELSE 0 END as "100%"
from goals
PSQL 示例:
select
count(*) filter(where statusstorie = false and statusTwentyFive = true and category not in ('goals') and space = 'personal') "25%",
count(*) filter(where statusstorie = false and statusFifty = true and category not in ('goals') and space = 'personal') "50%",
count(*) filter(where statusstorie = false and statusSeventyFive = true and category not in ('goals') and space = 'personal') "75%",
count(*) filter(where statusstorie = false and statusOneHundred = true and category not in ('goals') and space = 'personal') "100%"
from goals
注意:如果可能的话,我想将该函数复制到 MySQL
CREATE FUNCTION filter()
解决方案
这对你有用吗?
select
sum(CASE WHEN statusstorie = false and statusTwentyFive = true and category not in ('goals') and space = 'personal' THEN 1 ELSE 0 END) as "25%",
sum(CASE WHEN statusstorie = false and statusFifty = true and category not in ('goals') and space = 'personal' THEN 1 ELSE 0 END) as "50%",
sum(CASE WHEN statusstorie = false and statusSeventyFive = true and category not in ('goals') and space = 'personal' THEN 1 ELSE 0 END) as "75%",
sum(CASE WHEN statusstorie = false and statusOneHundred = true and category not in ('goals') and space = 'personal' THEN 1 ELSE 0 END) as "100%"
from goals
推荐阅读
- express - node-express 如何同时监听 localhost 和本地 IP?
- php - WordPress 自定义用户配置文件字段
- angular - 'npm i @auth0/angular-jwt' 中不存在 angular2-jwt 中的 AuthHttp 类
- node.js - CLI 应用程序(用 Node 编写)应该在哪里缓存东西?
- c# - 将复杂的类写入文件?
- ssl - 用于数据连接的 FTPS 客户端程序
- vba - 工作表的变量名
- c++ - 将图像复制到另一个图像的部分
- c# - 在 IIS 上托管 .NET Core API + 网站
- c - 如何使用 yarpgen 随机 C 程序生成器?