mysql 与 oracle 的查询语法有一部分不太相同,特别是在多表查询时,mysql 无法适应 oracle 的做外连接和右外连接的查询语法,自己有另外一套查询语法,与 ms sql server 相似。所以这里列举一下,方便以后查询和使用。
创建
create database dbname
create database dbname character set utf8
create database dbname character set utf8 collate utf8_general_ci
查看
show databases;
show create database dbname
修改
alter database dbname character set utf8
删除
drop database dbname
创建
create table tablename(tid int, tname varchar(20))
create table tablename(tid int, tname varchar(20)) character set utf8 collate utf8_general_ci
查看
show create table tablename
desc tablename
修改
rename table oldname to newname
alter table tablename add column height double
alter table tablename modify column height float
alter table tablename drop column height
alter table tablename character set utf8
删除
drop table tablename
当前时间
now()
日期加减
date_add(now(), INTERVAL 2 year)
date_sub(now(), INTERVAL 1 month)
date_add(now(), INTERVAL -1 day)
日期转换
select date_format(now(), ‘%Y-%m-%d’)
select date_format(now(), ‘%Y-%c-%d’);
select date_format(now(), ‘%Y-%c-%d %h:%i:%s’);
年月日
year(now())
month(now())
day(now())
select d.deptno, count(e.empno)
from dept d left outer join emp e /* 取 join 左侧表的数据 */
on d.deptno = e.deptno
group by d.deptno;
select d.deptno, count(e.empno)
from emp e right outer join dept d /* 取 join 右侧表的数据 */
on d.deptno = e.deptno
group by d.deptno;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有