Default Bonus

MediumSQLDatabaseSorting

Description

Write a SQL query to return each employee name and their bonus, substituting 0 when the bonus is null. Order by name ascending. **Output columns (in order):** name, bonus

Table:employees
ColumnType
idINT
nameTEXT
bonusINT

Examples

Input:CREATE TABLE employees (id INT, name TEXT, bonus INT); INSERT INTO employees VALUES (1,'Ann',500),(2,'Ben',NULL),(3,'Cal',100);
Output:Ann|500 Ben|0 Cal|100
Explanation:

A missing bonus is shown as zero while present bonuses pass through, ordered by name.

Input:CREATE TABLE employees (id INT, name TEXT, bonus INT); INSERT INTO employees VALUES (1,'Solo',NULL);
Output:Solo|0
Explanation:

A missing bonus is shown as zero while present bonuses pass through, ordered by name.

Input:CREATE TABLE employees (id INT, name TEXT, bonus INT); INSERT INTO employees VALUES (1,'A',1),(2,'B',2);
Output:A|1 B|2
Explanation:

A missing bonus is shown as zero while present bonuses pass through, ordered by name.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.