当前位置:Gxlcms > 数据库问题 > mysql基本操作(重点)

mysql基本操作(重点)

时间:2021-07-01 10:21:17 帮助过:29人阅读

10) not null, sex char(10) null, age int(5), phone bigint(11) ) studentinfo 为所创建的表名
  • 删除表
    drop table 表名;
  • 新增表数据
    # 一次增加一条数据
    
    insert into studentinfo (name,sex,age)
    values(黎诗,,12)
    #  一次增加多条数据
    
    insert into studentinfo (name,sex,age) values(黎诗,,21),(诗诗,,22)
    
    insert into 表名称 (字段名称,多个以,间隔) values (具体的值多个以,间隔)
  • 修改
    update studentinfo set name = 黎诗 where name = 小诗诗
  • 删除
    delete from 表名 where 条件

     

  • 三、数据库表的简单查询(一个简单小例子)

    1. 查询所有人员
      select * from people
    2. 只查询人员的姓名和年龄
      select p_name,p_age from people
    3. 查询年龄为20岁的人有哪些?
      select * from people where p_age = 20
    4. 查询60岁一下的人员有哪些?
      select * from people where p_age < 60
      
      查询年龄不等于60岁 的人员
      select * from people where p_age <> 60 (推荐,正式)
      
      select * from people  where p_age != 60 (非常规)
      
      常见的逻辑运算符 <, >, =, <=, >=, <>, !=
    5. 查询50岁以上并且工资大于8000的人员有哪些?
      select * from people where p_age > 50 || p_sal < 8000
      
      #  注意: and 用于连接两个条件 表示并且意思
      
      #           or 用于连接两个条件表示 或者意思
    6. 查询姓张的人员
      select * from people where p_name LIKE ‘张%‘,

      select * from prople wherer p_name LIKE ‘%张%‘
      # 中间有张字的
    7. 查询哪些人属于武当 华山 嵩山
      select * from people where p_menpai = 武当 or p_menpai = 华山 or p_menpai = 嵩山;
      
      
      
      select * from people where p_menpai in (武当,华山,嵩山);
      
      # 否:not in
    8. 查询工资在5000-8900的人员有哪些?
      select * from people where p_sal >= 5000 and p_sal <= 8900;
      
      select * from people where p_sal between 5000 and 8900;
    9. 查询所有人员,要求工资倒序排序
      select p_leader from people where p_sal > 3000 ORDER BY p_sal ask
    10. 查询年龄为21岁人员的领导者
      # select p_learder from people where p_age = ‘21‘
      
      # selecr * from people where p_id = ‘p003‘
      
      select * from people where p_id = (selest p_learder from ren where p_age = 21)

       

     

    mysql基本操作(重点)

    标签:推荐   显示   varchar   ike   val   数据库表   例子   逻辑运算   base   

    人气教程排行