SQL Server 使用SQL创建包含来自另一个表的聚合数据的表

ecfsfe2w  于 2023-01-25  发布在  其他
关注(0)|答案(1)|浏览(130)

我尝试从covid_deaths表的聚合数据创建tableau_table_1表。
这是我的疑问...

CREATE TABLE tableau_table_1 AS 
SELECT 
   SUM(new_cases) AS total_cases,
   SUM(cast(new_deaths as int)) AS total_deaths, 
   SUM(cast(new_deaths as int))/SUM(New_Cases)*100 AS death_percentage 
FROM
   covid_data..covid_deaths 
WHERE continent IS NOT NULL
 -- Group By date order by 1,2

我显示的错误是...

Incorrect syntax near the keyword 'from'
63lcw9qa

63lcw9qa1#

您可以尝试SELECT INTO语句

SELECT * INTO tableau_table_1
FROM (
   SELECT 
      SUM(new_cases) AS total_cases,
      SUM(cast(new_deaths AS int)) AS total_deaths, 
      SUM(cast(new_deaths AS int))/SUM(New_Cases)*100 AS death_percentage 
   FROM
      covid_data..covid_deaths 
   WHERE continent IS NOT NULL) AS aggregated_data;

相关问题