手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL创建查找数据部分练习

[日期:2013-01-15] 来源:Linux社区  作者:why0614 [字体:大 中 小]

#建立一个数据库
 
create database why;
 
#新建一个用户表
 
create table why(employee_id bigint,name char(16),gerder enum('M','F'),dept_id enum('caiwu','renshi','shichang','jishu'),join_time date,salary double,phone char(11),address char(40),description text);
 
#建立用户记录
 
insert into why values(20121200*(#序号),'name','F/M','caiwu/renshi/shichang/jishu','2012-10-07,*(#工资),'*'(#电话),'address','description')
 
#实现sql查询
 
    按名字查找
 
    select * from why where name='name'; #查找某个人的个人信息
 
    按照薪水>查找
 
    select * from why where salary>=3000 and salary<=10000;#查找薪水高于3000(含3000)    低于1w(含10000)的所有人
 
    查找每个部门的人数
 
    select dent_id,count(*) as dentsum from why group by dept_id;
 
    每个部门的平均薪资
 
    select dent_id,avg(salary) as avgsalary from why group by dept_id;
 
    描述字段为空的员工
 
    select * from why where description is null; #所有信息均为空(包括用户姓名) 

    select * from why where description='';#只有描述信息为空
 
    求出每个部门女员工工资最高的职工的薪水
 
    select dept_id max(salary) from why where gerder='F' group by dept_id;
 
    名字以l开头的员工个数
 
    select * from why where name like "l%"

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款