create table userlist(
username varchar(15) not null,
password char(1) not null,
useruid int(2) not null,
usergid int(2) not null ,
comment varchar(30),
homedir varchar(30),
shell varchar(18) not null,
index(username)
);
alter table userlist add id int(3) primary key auto_increment;
load data infile "/etc/passwd"
into table userlist
fields terminated by ":" lines terminat by "\n“;
//添加序列号,索引,自动增长。
select * from userdb.userlist
into outfile "/mysqlbak/userlist.txt"
fields terminated by ":"
lines terminated by "\n";
mysql> update userlist set username="root1" where username="root";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
3.6. 查看姓名和入职时间记录。
mysql> select name,entrytimes from yangongdb; +------+------------+ | name | entrytimes | +------+------------+ | jom | 1994 | | key | 2013 | | las | 1995 | | weis | 2011 | | pan | 1985 | | bar | 1993 | | tom | 1983 | | kela | 2003 | | kela | 2003 | | nos | 2003 | +------+------------+ |
3.7. 查询入职在2003年以前的员工信息。
mysql> select name,entrytimes from yangongdb where entrytimes<2003 ; +------+------------+ | name | entrytimes | +------+------------+ | jom | 1994 | | las | 1995 | | pan | 1985 | | bar | 1993 | | tom | 1983 | +------+------------+ 5 rows in set (0.00 sec) |
3.8. 查询tea部门工资最高的员工信息。
mysql> select name,postion,gz from yangongdb where postion="staff" order by gz desc limit 1 ; +------+---------+----------+ | name | postion | gz | +------+---------+----------+ | key | staff | 50000.99 | +------+---------+----------+ 1 row in set (0.00 sec) |
3.9. 统计女员工人数。
mysql> select count(gender) from yangongdb where gender="gril" ; +---------------+ | count(gender) | +---------------+ | 6 | +---------------+ 1 row in set (0.00 sec) |
3.10. 显示公司最早入职的2位员工姓名。
mysql> select name from yangongdb order by entrytimes asc limit 2; +------+ | name | +------+ | tom | | pan | +------+ 2 rows in set (0.00 sec) |
转载于:https://blog.51cto.com/linuxengineer/1347843