create table areas(id int primary key,atitle varchar(20),pid int,foreign key(pid) references areas(id));
source areas.sql;
select city.* from areas as cityinner join areas as province on city.pid=province.idwhere province.atitle=‘山西省‘;
select dis.*,dis2.* from areas as disinner join areas as city on city.id=dis.pidleft join areas as dis2 on dis.id=dis2.pidwhere city.atitle=‘广州市‘;
select sname,(select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘语文‘ and stuid=stu.id) as 语文,(select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘数学‘ and stuid=stu.id) as 数学,(select sco.score from scores sco inner join subjects sub on sco.subid=sub.id where sub.stitle=‘英语‘ and stuid=stu.id) as 英语from students stu;
select ascii(‘a‘);select char(97);select concat(12,34,‘ab‘);select length(‘abc‘);select substring(‘abc123‘,2,3);select trim(‘ bar ‘);select trim(leading ‘x‘ FROM ‘xxxbarxxx‘);select trim(both ‘x‘ FROM ‘xxxbarxxx‘);select trim(trailing ‘x‘ FROM ‘xxxbarxxx‘);select space(10);select replace(‘abc123‘,‘123‘,‘def‘);select lower(‘aBcD‘);select abs(-32);select mod(10,3);select 10%3;select floor(2.3);select ceiling(2.3);select round(1.6);select pow(2,3);select PI();select rand();select year(‘2016-12-21‘);select ‘2016-12-21‘+interval 1 day;日期格式化date_format(date,format),format参数可用的值如下
获取年%Y,返回4位的整数
* 获取年%y,返回2位的整数
* 获取月%m,值为1-12的整数
获取日%d,返回整数
* 获取时%H,值为0-23的整数
* 获取时%h,值为1-12的整数
* 获取分%i,值为0-59的整数
* 获取秒%s,值为0-59的整数
select date_format(‘2016-12-21‘,‘%Y %m %d‘);select current_date();select current_time();select now();