创建包含指示变量的表
确定 evanston311 数据中,中优先级和高优先级的请求是否更可能包含请求人联系方式:电子邮件地址或电话号码。
- 电子邮件包含一个 @。
- 电话号码的模式是 3 个字符、短横线、3 个字符、短横线、4 个字符。例如:555-555-1212。
使用 LIKE 来匹配这些模式。请记住,% 可匹配任意数量的字符(包括 0),而 _ 匹配单个字符。在模式前后加上 %(即将您的模式包裹在 % 中)可在其他文本中定位它。
例如,'%___.com%' 可以用来搜索对顶级域 '.com' 的引用,且其前至少有 3 个字符。
在临时表中创建并存储 email 和 phone 的指示变量。LIKE 的结果是 True 或 False,但将布尔值(True 或 False)转换为 integer 时,True 会变为 1,False 会变为 0。这样后续汇总会更方便。
本练习是课程的一部分
SQL 中的探索性数据分析
交互式实操练习
通过完成这段示例代码来试试这个练习。
-- To clear table if it already exists
DROP TABLE IF EXISTS indicators;
-- Create the indicators temp table
___ ___ ___ ___ AS
-- Select id
SELECT id,
-- Create the email indicator (find @)
CAST (description LIKE '___' AS integer) AS email,
-- Create the phone indicator
___ (___ ___ '___' AS integer) AS phone
-- What table contains the data?
FROM ___;
-- Inspect the contents of the new temp table
SELECT *
FROM indicators;