Forum Discussion

MrSaravani's avatar
MrSaravani
Copper Contributor
Feb 17, 2023

create table with one column from two fields min and max date from another table

I want to create table with one column from two fields min and max date from another table

  • HarshKumar994's avatar
    HarshKumar994
    Brass Contributor
    Consider you have an Order table CREATE TABLE orders ( order_id int PRIMARY KEY, order_date date ); We can create a new table called "date_range" with one column "range" that contains the minimum and maximum order dates from the "orders" table using the following SQL statement: CREATE TABLE date_range ( range daterange ); INSERT INTO date_range (range) SELECT daterange(MIN(order_date), MAX(order_date)) FROM orders;
  • olafhelper's avatar
    olafhelper
    Bronze Contributor
    Sorry, it's more then unclear what you mean. How does the bases table look like (DDL), then existing data (DML) and why a new table and not simply a view?

Resources