【发布时间】:2018-11-01 00:33:24
【问题描述】:
任何人都可以提供帮助或建议吗?我是 Oracle 新手,我有这个查询需要转换为 MySQL 查询
with dset as (
select count(column_1) as Volumes, to_char(creation_date,'MM-YYYY') as
Month, REPLACE(record_type, 3, 2) as RecordType from
table_1 where
transaction_type = 'PG' and
category = 'CCB' and
trunc(creation_date) >= to_date(?1, 'DD/MM/YYYY') and
trunc(creation_date) <= to_date(?2, 'DD/MM/YYYY')
group by to_char(creation_date,'MM-YYYY'), REPLACE(record_type, 3, 2)
)
SELECT x.DateMonth
,MAX(DECODE(x.RecordType, '1', x.Volumes)) CONSUMER
,MAX(DECODE(x.RecordType, '2', x.Volumes)) COMMERCIAL
FROM (
SELECT r.DateMonth
,r.RecordType
,r.Volumes
FROM dset r
) x
GROUP BY x.DatetMonth
让这个查询在 MySQL 中工作的最佳方法是什么。
非常感谢
【问题讨论】:
-
哪个版本的mysql?
-
@P.Salmon 我正在使用 SQL Server Managemnt Studio v17.6
-
SSMS 不是数据库(通常与 sql server 而非 oracle 或 mysql 一起使用)所以问题仍然是 mysql 的哪个版本?
-
我敢打赌,它还包含 Microsoft SQL Server 字样,如果出现此问题,则标记不正确(应标记为 sqlserver)。正确获取这些基本信息很重要 - mysql 和 sqlserver 不一样,如果对标签存在不确定性,最好的情况是您会得到延迟响应,最坏的情况是一个有效但不在您想要的数据库中的解决方案。
标签: mysql sql-server oracle