gpt4 book ai didi

python - 将 SQL 查询转换为 mongo 查询

转载 作者:行者123 更新时间:2023-11-29 19:30:21 36 4
gpt4 key购买 nike

我想将以下 SQL 转换为 mongo 查询:

SELECT brand_name,
count(`inventory`) AS totalstock,
count(if(`inventory`=0, `inventory`, NULL)) as outofstock,
count(if(`inventory`!=0, `inventory`, NULL)) as availablestock,
DATE_ADD(stock_updated_at, INTERVAL 318 minute) as stock_updated_at
FROM x group by Brand order by stock_updated_at desc;

我想在项目中找到 stock_updated_at,而不是在组中使用它。

这是我的 mongoquery

db.x.aggregate([     
{
"$group": {
"_id": { "Brand": "$Brand"},
"TotalStock": { "$sum": 1 },
"OutOfStock": { "$sum": ....
....
....

最佳答案

您可以尝试使用现有的转换器。 http://www.querymongo.com/

关于python - 将 SQL 查询转换为 mongo 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41822437/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com