我试图在子表中插入,从父表中获取[ACCNO] id及其计数值,然后在子表的FK中插入[ACCNO]并对每个[ACCNO]进行计数,但仍有一些错误那里
INSERT INTO [test1].[dbo].[star_schema]
(
[ACCNO],
[book_frequency])
VALUES
(SELECT [books_dimension] .ACCNO , count(books_dimension .[ACCNO]) as book_frequency
FROM [books_dimension]
group by [ACCNO] having (COUNT(*)>1) order by book_frequency desc)
GO
它在SELECT附近和最后一个括号中给出错误。 我还想在表[star_schema]中提到,id是star_int,它是identity -
答案 0 :(得分:2)
从select中插入时,您不需要VALUES
和ORDER BY
关键字,请执行以下操作:
INSERT INTO [test1].[dbo].[star_schema]([ACCNO], [book_frequency])
SELECT
[books_dimension].ACCNO,
count(books_dimension.[ACCNO]) as book_frequency
FROM [books_dimension]
group by [ACCNO]
having COUNT(*)>1