MySQL操作符与相关函数

union(联合)
union使用是关联两张表或者两个查询所查出来的数据,联合成一张表
但不会出现重复数据,显示的字段必须匹配列数。
select s3.id cid,s1.cityName province,s2.cityName city,s3.cityName district from s_provinces s1
  right join s_provinces s2 on s2.parentId = s1.id
  right join s_provinces s3 on s3.parentId = s2.id
union
select s2.id,s1.cityName,s2.cityName,null from s_provinces s1
  right  join s_provinces s2 on s2.parentId = s1.id ;
union all
union则联合查询的出来的条数全部,不会去除重复。
concat(函数)
concat(参数,参数)任何一个参数为null则返回null


单独的distinct只能放在开头,否则报错,语法错误

时间相关函数
#查询当前日期前一个月内数据有多少
select * from lagou_position  
where Date(published_at) > Date(date_sub(now(),interval '30 0:0:0' day_second));#date_sub是时间减法函数
#求叁数日期是星期几  (每周日作为一周的开始)
select * from lagou_position where dayofweek(updated_at) = 2 limit 10;
extract()
 
原文地址:https://www.cnblogs.com/dzcici/p/9642587.html