首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Mysql查询到PostgreSQL查询

Mysql查询到PostgreSQL查询
EN

Stack Overflow用户
提问于 2020-12-11 18:41:04
回答 2查看 45关注 0票数 0
代码语言:javascript
运行
复制
select storeID, itemID, custID, sum(price)
from Sales F
group by storeID, custID, itemID 
    with cube(storeID, custID);

我打算在postgreSQL中使用此查询,但它不能直接在postgreSQL中工作,如何将此查询转换为postgreSQL查询?

EN

回答 2

Stack Overflow用户

发布于 2020-12-11 20:00:06

您的代码将在没有with关键字的情况下工作:

代码语言:javascript
运行
复制
select storeID, itemID, custID, sum(price)
from Sales F
group by itemID, cube(storeID, custID);

我更喜欢使用分组集来表示分组:

代码语言:javascript
运行
复制
select storeID, itemID, custID, sum(price)
from Sales F
group by grouping sets ( (storeID, custID, itemID),
                         (custID, itemID),
                         (storeID, itemID),
                         (itemID)
                       );

如果我理解你想要做什么,这应该是完全相同的。

也可以使用cube,然后使用filter:

代码语言:javascript
运行
复制
select storeID, itemID, custID, sum(price)
from Sales F
group by cube(storeID, custID, itemID)
having itemId is not null
票数 1
EN

Stack Overflow用户

发布于 2020-12-11 18:44:44

试试这个:

代码语言:javascript
运行
复制
select storeID, itemID, custID, sum(price)
from Sales F
group by cube (storeID, itemID, custID)

有关CUBEGROUPING SETSROLLUP.的更多详细信息,请查看this post

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65249764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档