gpt4 book ai didi

sql - 在sql server cte中获取 "No column was specified for column 2 of ' d'"?

转载 作者:行者123 更新时间:2023-12-02 00:33:19 25 4
gpt4 key购买 nike

我有这个查询,但它没有按预期工作,

with c as (select 
month(bookingdate) as duration,
count(*) as totalbookings
from
entbookings
group by month(bookingdate)
),
d as (SELECT
duration,
sum(totalitems)
FROM
[DrySoftBranch].[dbo].[mnthItemWiseTotalQty] ('1') AS BkdQty
group by duration
)

select
c.duration,
c.totalbookings,
d.bkdqty
from
c
inner join d
on c.duration = d.duration

当我运行这个时,我得到

Msg 8155, Level 16, State 2, Line 1
No column was specified for column 2 of 'd'.

谁能告诉我我做错了什么吗?

另外,当我运行这个时,

with c as (select 
month(bookingdate) as duration,
count(*) as totalbookings
from
entbookings
group by month(bookingdate)
),
d as (select
month(clothdeliverydate),
SUM(CONVERT(INT, deliveredqty))
FROM
barcodetable
where
month(clothdeliverydate) is not null
group by month(clothdeliverydate)
)

select
c.duration,
c.totalbookings,
d.bkdqty
from
c
inner join d
on c.duration = d.duration

我明白

Msg 8155, Level 16, State 2, Line 1
No column was specified for column 1 of 'd'.
Msg 8155, Level 16, State 2, Line 1
No column was specified for column 2 of 'd'.

最佳答案

您只需为 CTE 中的聚合列提供别名

d as (SELECT 
duration,
sum(totalitems) as sumtotalitems
FROM
[DrySoftBranch].[dbo].[mnthItemWiseTotalQty] ('1') AS BkdQty
group by duration
)

关于sql - 在sql server cte中获取 "No column was specified for column 2 of ' d'"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12119073/

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