Table

orders

6 columns · 1 foreign keys · referenced by 1 tables

Columns

#NameTypeKey
01order_idSERIALPK
02cust_idINTFK
03order_dateTIMESTAMP
04statusVARCHAR(30)
05totalNUMERIC
06shipped_atTIMESTAMP

Outgoing references

  • cust_id — references another table

Referenced by

Example queries against this table

  1. Select all orders with NULL shipped_at (not shipped)
    SQL
    SELECT order_id, cust_id, order_date, status
    FROM orders
    WHERE shipped_at IS NULL;
  2. Show total revenue from all orders
    SQL
    SELECT
      SUM(total) AS total_revenue,
      COUNT(*) AS order_count,
      ROUND(AVG(total), 2) AS avg_order_value
    FROM orders
    WHERE status = 'completed';
  3. Find all orders NOT in pending or cancelled status
    SQL
    SELECT order_id, cust_id, total, status
    FROM orders
    WHERE status NOT IN ('pending', 'cancelled')
    ORDER BY order_date DESC;
  4. Find orders placed in the last 30 days
    SQL
    SELECT order_id, cust_id, order_date, total
    FROM orders
    WHERE order_date >= NOW() - INTERVAL '30 days'
    ORDER BY order_date DESC;