gpt4 book ai didi

sql - 划分两个查询的输出

转载 作者:行者123 更新时间:2023-11-29 14:18:01 26 4
gpt4 key购买 nike

我想编写一个查询,输出 a/c(a 除以 c)按名为 cobrand_id 的变量分组。

编写此查询的最无缝方式是什么?谢谢。

    select sum(calc) a, cobrand_id b 
from temp_08.jwn_calc
where optimized_transaction_date > '2015-10-31'
and optimized_transaction_date <= '2015-10-31' + 45
GROUP BY cobrand_id

select sum(calc) c, cobrand_id d
from temp_08.jwn_calc
where optimized_transaction_date > '2015-10-31'
and optimized_transaction_date <= '2015-10-31' + 91
GROUP BY cobrand_id

最佳答案

您可以将现有查询用作子查询并将它们连接起来以划分 a/c

Select q1.b, q1.a/q2.c as result
From (your first query) q1
Inner join (your second query) q2 on q1.b = q2.d

关于sql - 划分两个查询的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41202554/

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