mysql程序语句范文_MySQL基本语句
1、查看當(dāng)前使用的是哪個(gè)數(shù)據(jù)庫(kù)
mysql> select database();
另外,在下面2個(gè)語(yǔ)句的輸出里也能看出當(dāng)前庫(kù)是哪一個(gè)
mysql> show tables;
mysql> status;
2、查看MySQL版本和狀態(tài)
mysql> select VERSION();
mysql> status;
3、查看MySQL實(shí)例的當(dāng)前狀態(tài)(參數(shù)形式)
mysql> show status;
4、查看MySQL實(shí)例的參數(shù)
mysql> show variables;
查看最大連接數(shù)
mysql> show variables like ‘%max_connections%‘;
5、查看MySQL實(shí)例當(dāng)前的進(jìn)程
mysql> show processlist;
6、查詢(xún)所有數(shù)據(jù)
select * from Info 查所有數(shù)據(jù)
select Code,Name from Info 查特定列
7、根據(jù)條件查
select * from Info where Code=‘p001‘ 一個(gè)條件查詢(xún)
select * from Info where Code=‘p001‘ and Natio n=‘n001‘ 多條件 并關(guān)系 查詢(xún)
select * from Info where Name=‘胡軍‘ or Nation=‘n001‘ 多條件 或關(guān)系 查詢(xún)
select * from Car where Price>=50 and Price<=60 范圍查詢(xún)
select * from Car where Price between 50 and 60 范圍查詢(xún)
8、模糊查詢(xún)
select * from Car where Name like ‘%型‘ %通配符代表任意多個(gè)字符
select * from Car where Name like ‘%奧迪%‘
select * from Car where Name like ‘_馬%‘?_通配符代表任意一個(gè)字符
9、排序
select * from Car order by Price asc 按照價(jià)格升序排列
select * from Car order by Price desc 按照價(jià)格降序排列
select * from Car order by Price,Oil 按照兩列進(jìn)行排序,前面的為主要的
10、統(tǒng)計(jì)函數(shù)(聚合函數(shù))
select count(Code) from Car 查詢(xún)表中有多少條數(shù)據(jù)
select max(Price) from Car 取價(jià)格的最大值
select min(Price) from Car 取價(jià)格的最小值
select sum(Price) from Car 取價(jià)格的總和
select avg(Price) from Car 取價(jià)格的平均值
11、分組查詢(xún)
select Brand from Car group by Brand having count(*)>2 查詢(xún)所有系列中數(shù)量大于2的
12、分頁(yè)查詢(xún)
select * from Car limit 0,5 跳過(guò)幾條數(shù)據(jù)取幾條數(shù)據(jù)
13、去重查詢(xún)
select distinct Brand from Car
14、查詢(xún)建庫(kù)、建表語(yǔ)句
mysql> show create database dbname;
指定庫(kù)后才能查詢(xún)建表語(yǔ)句
mysql> show create table tablename;
15、查詢(xún)指定表的字段屬性
mysql> show full columns from tablename;
或者
mysql> show full fields from tablename;
總結(jié)
以上是生活随笔為你收集整理的mysql程序语句范文_MySQL基本语句的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 静电场问题的解法
- 下一篇: 移动应用开发相关法律法规