【发布时间】:2012-08-20 14:08:00
【问题描述】:
我有这个查询,但它没有正常工作,
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
当我运行它时,我得到了
消息 8155,第 16 级,状态 2,第 1 行
没有为“d”的第 2 列指定任何列。
谁能告诉我我做错了什么?
另外,当我运行这个时,
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
我明白了
消息 8155,第 16 级,状态 2,第 1 行
没有为“d”的第 1 列指定任何列。
消息 8155,第 16 级,状态 2,第 1 行
没有为“d”的第 2 列指定任何列。
【问题讨论】:
-
你还需要知道如何拥有 netBalance 吗?
标签: sql sql-server group-by common-table-expression calculated-columns