SQL 必知必会第八课 使用函数处理数据
select vend_name, upper(vend_name) as vend_name_upcase from vendors order by vend_name;
select cust_name, cust_contact from customers where cust_contact = 'Michael Green';
select cust_name, cust_contact from customers where soundex(cust_contact) = soundex('Michael Green');
##soundex是将文本转换为语音表示的字母数字模式,可以用来搜索发音相似的数据
select order_num from orders where extract(year from order_date) = 2020;
select order_num from orders where year(order_date) = 2020;
##challenges
select cust_id, cust_name,upper(concat(substring(cust_contact,1,2),substring(cust_city,1,3))) as user_login from Customers ; -- 1
## substring(expression, start, length) start第一位是1 不是0 和其他编程语言不一样
select order_num, order_date from orders order by date(order_date); -- 2
注意点
- 数据处理函数在格式化,处理和过滤数据中非常有用,但是在SQL的实现中非常不一致。