Event Type Pivot
HardSQLDatabaseMathSorting
Description
Write a SQL query that returns one row with the number of 'click' events as clicks and the number of 'view' events as views from the events table. **Output columns (in order):** clicks, views
Table:
events| Column | Type |
|---|---|
| id | INT |
| type | TEXT |
Examples
Input:
CREATE TABLE events (id INT, type TEXT); INSERT INTO events VALUES (1,'click'),(2,'view'),(3,'click'),(4,'view'),(5,'view');Output:
2|3Explanation:
Conditional sums turn the two event types into side-by-side columns of counts in a single row.
Input:
CREATE TABLE events (id INT, type TEXT); INSERT INTO events VALUES (1,'click');Output:
1|0Explanation:
Conditional sums turn the two event types into side-by-side columns of counts in a single row.
Input:
CREATE TABLE events (id INT, type TEXT); INSERT INTO events VALUES (1,'view'),(2,'view');Output:
0|2Explanation:
Conditional sums turn the two event types into side-by-side columns of counts in a single row.
Constraints
- •
Use standard SQL (SQLite).