第一题
主要考察
● CONCAT 用来拼接字符串
● LEFT 从左边截取字符
● RIGHT 从右边截取字符
● UPPER 变为大写
● LOWER 变为小写
● SUBSTRING 截取字符串
select user_id,
concat (
upper(left(name,1)) ,
lower(right(name,length(name)-1))
) as 'name'
from Users
order by user_id;
第二题
考察点:
order by
group by 和 count()
distinct
group_concat
select sell_date, count(distinct product) as num_sold, group_concat(distinct product) as products
from Activities
group by sell_date
order by sell_date;
第三题
考察点主要在正则表达式上
^DIAB1 表示以 DIAB1 开头
| 表示 或者
. 表示任意一个字符
’*‘ 表示重复0到无穷多个的前一个字符 第一个
\ 表示转义字符
\s 表示空白,包括空格、换行、Tab 缩进等所有的空白
’. *\sDIAB1‘ 表示DIAB1前是空格 且空格前有0到无穷多个的任意字符
select patient_id, patient_name, conditions
from Patients
where conditions rlike '^DIAB1|.*\\sDIAB1';