sql,用COALESCE,NULLIF对空值和null值进行处理

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

SQL CODE:

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

select result:

id  name    price   card_name   card_number transaction_date
2   Intelligent Aluminum Keyboard   88.51   Emmitt Durgan   1234-2121-1221-1211 2011-12-18
9   Aerodynamic Aluminum Shoes  62.82   Rosalinda Von   1212-1221-1121-1234 2012-08-14
10  Rustic Marble Watch 72.35   Owen Jerde PhD  1234-2121-1221-1211 2015-10-09
12  [product name not found]    97.89   Kali Mante  1211-1221-1234-2201 2010-07-19
14  Sleek Rubber Lamp   94.13   Lauryn McClure  1211-1221-1234-2201 2012-12-12
15  Gorgeous Wooden Clock   84.73   Niko Cartwright 1234-2121-1221-1211 2016-01-17
17  Durable Linen Knife 73.95   Robb Ruecker Sr.    1234-2121-1221-1211 2011-02-20

你可能感兴趣的:(Mysql,sql)