Bird
0
0

If a view is created as CREATE VIEW recent_orders AS SELECT * FROM orders WHERE order_date > current_date - interval '7 days', what will SELECT COUNT(*) FROM recent_orders; return?

medium📝 query result Q5 of 15
PostgreSQL - Views and Materialized Views
If a view is created as CREATE VIEW recent_orders AS SELECT * FROM orders WHERE order_date > current_date - interval '7 days', what will SELECT COUNT(*) FROM recent_orders; return?
AThe number of orders placed in the last 7 days
BThe total number of orders in the table
CAn error because interval syntax is invalid
DZero, because views do not store data
Step-by-Step Solution
Solution:
  1. Step 1: Understand the view filters orders by recent dates

    The view selects orders with order_date within the last 7 days.
  2. Step 2: COUNT(*) on the view counts matching rows

    The query counts how many orders satisfy that date condition.
  3. Final Answer:

    The number of orders placed in the last 7 days -> Option A
  4. Quick Check:

    View filters recent orders = C [OK]
Quick Trick: COUNT on a view counts rows matching its query [OK]
Common Mistakes:
  • Confusing view with stored data
  • Thinking interval syntax is wrong
  • Assuming COUNT returns total table rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes