Which statement creates a simple view named recent_orders showing orders from the last 30 days?

Study for the SQL Basics Test. Explore multiple-choice questions with comprehensive explanations and hints. Gear up for your SQL exam!

Multiple Choice

Which statement creates a simple view named recent_orders showing orders from the last 30 days?

Explanation:
The concept being tested is creating a simple view that shows only records within a recent time window by filtering on a date. To get the last 30 days, you compare the order_date to today's date minus 30 days. Using CURRENT_DATE returns today, and subtracting INTERVAL '30 days' yields the cutoff date. Then keeping order_date greater than that cutoff returns only orders from the last 30 days. Wrapping this in a single CREATE VIEW ... AS SELECT * FROM orders WHERE ... makes a straightforward view definition. That statement uses exactly this pattern, so it creates a view named recent_orders that shows orders from the last 30 days. The other options either omit the filter (returning all orders), use an invalid comparison (comparing a date to a numeric value like "30 days"), or widen the window to 60 days.

The concept being tested is creating a simple view that shows only records within a recent time window by filtering on a date. To get the last 30 days, you compare the order_date to today's date minus 30 days. Using CURRENT_DATE returns today, and subtracting INTERVAL '30 days' yields the cutoff date. Then keeping order_date greater than that cutoff returns only orders from the last 30 days. Wrapping this in a single CREATE VIEW ... AS SELECT * FROM orders WHERE ... makes a straightforward view definition.

That statement uses exactly this pattern, so it creates a view named recent_orders that shows orders from the last 30 days. The other options either omit the filter (returning all orders), use an invalid comparison (comparing a date to a numeric value like "30 days"), or widen the window to 60 days.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy