去重 例如
select a from table_A group by a
select DISTINCT a from table_a
合并 例如
去重并排序合并
[SQL 语句 1]
UNION
[SQL 语句 2]
或者
不去重 直接拼接
[SQL 语句 1]
UNION All
[SQL 语句 2]
join相关
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
inner join(等值连接) 只返回两个表中联结字段相等的行
select * from a left join b on a.xx = b.xx
聚集函数
avg
count
max
min
sum
用于处理字符串的函数
合并字符串函数:concat(str1,str2,str3…)
比较字符串大小函数:strcmp(str1,str2)
获取字符串字节数函数:length(str)
获取字符串字符数函数:char_length(str)
字母大小写转换函数:大写:upper(x),ucase(x);小写lower(x),lcase(x)
处理数值函数
绝对值函数:abs(x)
向上取整函数:ceil(x)
向下取整函数:floor(x)
取模函数:mod(x,y)
随机数函数:rand()
四舍五入函数:round(x,y)
数值截取函数:truncate(x,y)
用于处理时间日期的函数
获取当前日期:curdate(),current_date()
获取当前时间:curtime(),current_time()
获取当前日期时间:now()
从日期中选择出月份数:month(date),monthname(date)
从日期中选择出周数:week(date)
从日期中选择出周数:year(date)
从时间中选择出小时数:hour(time)
从时间中选择出分钟数:minute(time)
从时间中选择出今天是周几:weekday(date),dayname(date)
判断
if(Column = xx ,xx,yy)
这里等同于
if(Column == xx ){
Column = xx;
} else {
Column = yy;
}
case when Column = xx then xx else yy end
等同于上面的if else