-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkyu6_SQL_Basics_simple_null_handling.sql
More file actions
34 lines (33 loc) · 1.01 KB
/
kyu6_SQL_Basics_simple_null_handling.sql
File metadata and controls
34 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-- SQL Basics: Simple NULL handling
--
-- https://www.codewars.com/kata/5811315e04adbbdb5000050e/train/sql
--
-- For this challenge you need to create a SELECT statement, this select statement must have NULL handling, using
-- COALESCE and NULLIF;
--
-- If no name is specified you must replace with [product name not found];
-- If no card_name is specified you must replace with [card name not found];
-- If no price is specified you must throw away the record, you must also filter the dataset by prices greater than 50;
--
-- eusales table schema
-- id
-- name
-- price
-- card_name
-- card_number
-- transaction_date
--
-- resultant table schema
-- id
-- name
-- price (greater than 50.00)
-- card_name
-- card_number
-- transaction_date
SELECT id,
COALESCE(NULLIF(name, ''), '[product name not found]') AS name,
price,
COALESCE(NULLIF(card_name, ''), '[card name not found]') AS card_name,
card_number,
transaction_date
FROM eusales WHERE price >= 50.0;