MySQL語句

在安裝在mysql之后,還沒有用可視化的軟件使用數(shù)據(jù)庫,我們只能使用cmd 終端 來創(chuàng)建并使用數(shù)據(jù)庫,接下來我們就看看在cmd中如何使用數(shù)據(jù)庫吧.
首先我們在進入到mysql之后使用語句 查看所有的數(shù)據(jù)庫.

show databases
然后是 創(chuàng)建數(shù)據(jù)庫 persondb數(shù)據(jù)庫名

create database [if not exists] persondb

使用 切換數(shù)據(jù)庫

use persondb

展示所有的表格

show tables

創(chuàng)建表

create table user_table(id int,perid int,name varchar(20),joy varchar(50))engine='innoDB' default charset='utf8';

插入信息

insert into user_table(id,perid,name,joy) values(1,1,'nana','銷售員');

查找所有信息

select *from user_table;

新增字段

alter table user_table add(jiangj int,gongzi int);

更新信息

update user_table set jiangj = 1000,gongzi =6000 where id = 1;

刪除信息

delete from user_table where id = 1;

刪除表

drop table user_table;

刪除數(shù)據(jù)庫

drop database persondb;

修改字段的類型和名字

alter table [表名字] change [舊字段] [新字段] [新字段的類型] [新字段的約束]

刪除字段

alter table [表名字] drop 字段

找出獎金高于工資零點六的員工

select * from user_table where jiangj >gongzi * 0.6;

找出部門編號為1中所有經(jīng)理,部門編號為2中所有銷售員,還有既不是不銷售員又不是經(jīng)理但其工資大于或等于2000的所有員工的詳資料

select * from user_table where (perid = 1 and joy ='messness')or(perid = 2 and joy = 'xiaoshou') or (joy not in('messness','xiaoshou')and gongzi >= 2000);

查詢所有員工按工資排序

select *from user_table order by gongzi;

查詢每個部門的平均工資

select perid,avg(gongzi) from user_table group by perid;

查詢每種工作的,最高工資,最低工資, 人數(shù)

select joy,max(gongzi),min(gongzi),count(*) from user_table group by joy;

查詢出’文員’, ‘銷售員’工種下,所有人的工資總和

select joy,sum(gongzi) from user_table where joy in ('wenyuan','xiaoshou')group by joy;

查詢出每個工種下人數(shù)大于2的工種并顯示其人數(shù);

select joy,count()from user_table group by joy having count() >2;

排序

select score from scoreTable order by score // 升序
select * from scoreTable order by score desc // 降序

函數(shù)

count() 統(tǒng)計個數(shù)
max() 最大值
min() 最小值
avg() 平均值

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 1、說明:創(chuàng)建數(shù)據(jù)庫CREATE DATABASE database-name2、說明:刪除數(shù)據(jù)庫drop dat...
    codeSirCao閱讀 502評論 0 2
  • DDL:對數(shù)據(jù)庫,表,列進行操作DDL:對數(shù)據(jù)庫,表,列進行操作 關鍵字:create 創(chuàng)...
    追逐的夢境閱讀 326評論 0 0
  • 轉(zhuǎn)自:http://www.lai18.com/content/7451585.html 基本操作 查看數(shù)據(jù)庫 指...
    光光李閱讀 966評論 0 5
  • 正畸, 也就是我們常說的戴牙套、牙齒矯正, 最主要的目的:排齊牙齒,調(diào)整咬合 很多人都會有誤區(qū),認為有嚴重齙牙才需...
    洋蔥說閱讀 1,111評論 0 2
  • 看到趙彬潔轉(zhuǎn)的“十幾年后,書桓去了我是歌手,依萍的研究生畢業(yè)作賣了好幾億,如萍變成電視劇制作人,杜飛轉(zhuǎn)型做導演,雪...
    七絆閱讀 295評論 0 1

友情鏈接更多精彩內(nèi)容