在數(shù)據(jù)清洗中,SQL CASE WHEN語句可以用來根據(jù)特定條件對(duì)數(shù)據(jù)進(jìn)行處理和轉(zhuǎn)換。以下是一些在數(shù)據(jù)清洗中使用SQL CASE WHEN的示例:
SELECT
CASE
WHEN column_name = 'A' THEN 1
WHEN column_name = 'B' THEN 2
ELSE 0
END AS numeric_column
FROM table_name;
SELECT
CASE
WHEN column_name IS NULL THEN 'Unknown'
ELSE column_name
END AS filled_column
FROM table_name;
SELECT
CASE
WHEN column_name >= 0 AND column_name < 100 THEN '0-99'
WHEN column_name >= 100 AND column_name < 200 THEN '100-199'
ELSE '200+'
END AS group_column
FROM table_name;
通過以上示例,可以看到SQL CASE WHEN語句在數(shù)據(jù)清洗中的應(yīng)用是非常靈活的,可以根據(jù)具體的數(shù)據(jù)處理需求進(jìn)行相應(yīng)的處理和轉(zhuǎn)換。