Insert using SELECT

Insert using SELECT

Easy SQL DML 19 views
Explanation Complexity

Problem Statement

Create a backup table OrdersBackup and copy only last month's orders into it (full rows).

Input Format

SQL DDL + DML

Output Format

Table + rows created

Example

Orders(order_date, ...)
Backup filled

Constraints

Assume PostgreSQL-style DATE_TRUNC

Input / Output Format

Input Format
SQL DDL + DML
Output Format
Table + rows created
Constraints
Assume PostgreSQL-style DATE_TRUNC

Examples

Input:
Orders(order_date, ...)
Output:
Backup filled

Example Solution (Public)

SQL
CREATE TABLE OrdersBackup AS SELECT * FROM Orders WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND order_date < DATE_TRUNC('month', CURRENT_DATE);

Official Solution Code

CREATE TABLE OrdersBackup AS SELECT * FROM Orders WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND order_date < DATE_TRUNC('month', CURRENT_DATE);
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.