在SQL中从select查询创建一个表

时间:2014-06-24 18:14:40

标签: sql sql-server sql-server-2012

  Select    
    Books.IdBooks,
    Books.Title,
    Books.Author,
    COUNT(Books.IdBooks) as NumberOfOrderedBooks

    From Books
    right join Orders
      on (Books.IdBooks = Orders.IdBooks)
    group by
        Books.IdSeminar,
        Books.Naziv

这个选择查询工作正常,但我想在SQL 2012中从这个查询创建表,我不知道该怎么做。

提前致谢

1 个答案:

答案 0 :(得分:1)

如果我了解你,你可以使用INTO CLAUSE之类的,

Select    
  Books.IdBooks,
  Books.Title,
  Books.Author,
  COUNT(Books.IdBooks) as NumberOfOrderedBooks
Into NEW_TABLE
From Books
right join Orders
  on (Books.IdBooks = Orders.IdBooks)
group by
    Books.IdSeminar,
    Books.Naziv