18---sql 語句

 

1.       創建數據庫
./usr/local/mysql/bin/mysql
Show databases;
Create database rx;
2.       創建表
Use rx;
Create yg.rx (employee_id int,name char(10), gender enum(‘M’,’W’), dept_id set (1,2,3,4), join_time date, salary int, phone int, address char(10), description char(10));
 ##查看創建表
Desc yg;
3.       向表中添加數據
Insert  into yg values(1,”xingxing”,’M’,’1’, ‘2010-12-16’, 2500,138350,’beijing’, ‘yg’);
4.       表中數據出錯的修改方式
Update yg set employee_id=8 where name=’xingxing’;
##列屬性的修改
Alter table yg modify address char(20);
5.       查詢表中某個人的記錄
Select * from yg where name=”xingxing”;
6.       按薪水查找大於3000的
Select name,salary>=3000 from yg;
Select * from yg where salary>=3000;
7.       每個部門有多少人
4個部門:
Select count(*) from yg group by dept_id;
每個部門;
Select count(*) from yg group by dept_id having dept_id=’2’;
8.       每個部門的平均工資
Select avg(salary) from yg group by dept_id;
Select avg(salary) from yg group by dept_id having dept_id=’1’;
9.       是否有人描述字符爲空
##添加空字符的描述
Insert into yg values();
Insert into yg values(10,”niy”, ’M’, ’1’, ”2003-12-10”,1223,138,null,null);
Select * from yg where name is null;
10.   每個部門賺的最多的人
Select name,mix(salary) from yg group by debt_id;
Select name,mix(salary) from yg group by debt_id having debt_id=’1’;
11.   名字是以l 開頭
Select name from yg where name like ”l%”;
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章