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
ColumnType
idINT
typeTEXT

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|3
Explanation:

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|0
Explanation:

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|2
Explanation:

Conditional sums turn the two event types into side-by-side columns of counts in a single row.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.