简体   繁体   English

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

[英]Create table with aggregate data from another table, using SQL

I am trying to create the tableau_table_1 table from the aggregated data of the covid_deaths table.我正在尝试根据 covid_deaths 表的聚合数据创建 tableau_table_1 表。

Here is my query...这是我的查询...

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

The error that I am showing is...我显示的错误是......

Incorrect syntax near the keyword 'from'

You could try SELECT INTO Statement你可以试试 SELECT INTO Statement

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用另一个表中的数据创建SQL表 - Create SQL table with the data from another table 在Oracle SQL中使用来自另一个表的数据创建一个新表 - Create a new table in Oracle SQL with data from another table SQL创建新表并从另一个表插入数据 - SQL create new table and insert data from another table 如何使用 SQL 在 spark 中的另一个 TABLE 中使用 SELECT 创建一个 TABLE - How to create a TABLE with SELECT from another TABLE in spark using SQL SQL从具有聚合功能的另一个表插入表变量? - SQL to insert into table variable from another table with aggregate function? SQL Update查询使用多个字段更新来自另一个表的汇总值的表 - SQL Update Query to update a table with aggregate value from another table using multiple fields 如何通过汇总另一个表中另一个列的数据来创建派生列 - how to I create a derived column by aggregate data from another column in another table 使用PL / SQL将数据从表插入到另一个表 - Insert data from table to another table using PL/SQL 更新一个表使用SQL中另一个表的数据 - Updating one table Using data from another table in SQL 使用mySql(phpMyAdmin)创建一个从另一个表中获取数据的表 - Create a table that take data from another table using mySql (phpMyAdmin)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM