1、創(chuàng)建測試表,
成都創(chuàng)新互聯(lián)公司主營任丘網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),任丘h5重慶小程序開發(fā)搭建,任丘網(wǎng)站營銷推廣歡迎任丘等地區(qū)企業(yè)咨詢
create table test_date1(id int, v_date date);
2、插入測試數(shù)據(jù)
insert into test_date1 values(1,str_to_date('2019-08-01','%Y-%m-%d'));
insert into test_date1 values(2,str_to_date('2019-10-01','%Y-%m-%d'));
insert into test_date1 values(3,str_to_date('2019-08-05','%Y-%m-%d'));
insert into test_date1 values(4,str_to_date('2019-09-09','%Y-%m-%d'));
commit;
3、查詢表中全量數(shù)據(jù),select t.* from test_date1 t;
4、編寫語句,查詢date類型字段,日期大于20190901的數(shù)據(jù);
select t.* from test_date1 t where v_date str_to_date('2019-09-01','%Y-%m-%d');
1、進入information_schema
數(shù)據(jù)庫(存放了其他的數(shù)據(jù)庫的信息)
use
information_schema;
2、查詢所有數(shù)據(jù)的大小:
select
concat(round(sum(data_length/1024/1024),2),'MB')
as
data
from
tables;
3、查看指定數(shù)據(jù)庫的大?。?/p>
比如查看數(shù)據(jù)庫home的大小
select
concat(round(sum(data_length/1024/1024),2),'MB')
as
data
from
tables
where
table_schema='home';
在插入數(shù)據(jù)庫之前先做一個判斷
boolean ifExists=false;
String insertUser,strSql="select user from emp";
stmt.executeUpdate(sql);
while( stmt.next){
if(insertUser.equals(stmt.getString("user"))){
ifExists=true;
break;
}
}
if( ifExists){
system.out.println("用戶已存在");
}else{
String sql = "insert into emp values('"+ num +"' )"; stmt.executeUpdate(sql);
System.out.println("恭喜你同志添加成功!");
}
select * from 表名
where cast(id as unsigned int) =1000 and cast(id as unsigned int)1010;
字符串比較式一位一位比較的,要轉(zhuǎn)成數(shù)字類型才能按大小比較
1、查詢整個mysql數(shù)據(jù)庫,整個庫的大小;單位轉(zhuǎn)換為MB。
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data? from information_schema.TABLES
2、查詢mysql數(shù)據(jù)庫,某個庫的大??;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
3、查看庫中某個表的大??;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name = 'test_a';
4、查看mysql庫中,test開頭的表,所有存儲大??;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name like 'test%';
字符串比較大小不是比較長短
從第一個字符開始比較,相同相等,遇到不同就比較出來了abc,根據(jù)ascii碼比較的
abcdabcde