Oracle
查看所有表的名字:
select table_name from user_tables;
查询特定表的名字:
select * from (select table_name t from user_tables) newt where newt.t LIKE '%CODE%';
复杂的查询、分组、排序、计算示例:
select (sum(ss)/count(p)) from (select t.provinceid p,sum(t.time_difference)/count(*) ss from mobile_balancequery t
where (t.queryresult = 0 or t.queryresult = 81029) and t.start_querytime > sysdate - 300/1440
group by t.provinceid
order by t.provinceid)
去除重复数据:
delete from mobile_balancequery a
where rowid not in
(select max(rowid) from mobile_balancequery b where a.phonenum = b.phonenum);
commit;
MySQL :
1、查看表的存储引擎
show create table article; -- article 是表名
2、查看所有使用数据库的进程
show processlist;
3、杀死进程
kill 57; -- 57是进程号 可以通过 show processlist 查找
4、查看主从状态
show slave statusG
双yes就是从库,双no可能是主库
5、开启、关闭从库
start slave
stop slave
6、MySQL 命令窗登录、退出(exit)
mysql -h192.168.61.28 -P3306 -utest -ptest -- 注意P大写
7、查看表的创建语句
show create table tableName;
8、查看数据库、切换数据库、查看数据库的表
show databases; -- 查看所有数据库名 show tables; -- 查看家数据库中所有表名 use databaseName; -- 切换数据库
9、查看表的大小
-- 首先切换到管理库 use information_schema; -- 执行如下语句(weather是数据库名,cms_data是表名) select data_length,index_length from tables where table_schema='weather' and table_name = 'cms_data'; select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB, concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB from tables where table_schema='weather' and table_name = 'cms_data';