题目1:MySQL基本练习【单、多表】

一、 选择题(每题3分,满分30分)列出客户订单总金额大于3000的数据,正确的是( )A. select C_ID,sum(orderAmount) from t_orders group by C_ID having sum(orderAmount)>3000;B. select C_ID,sum(orderAmount) from t_orders where sum(orderAmount)>3000 group by C_ID;C. select C_ID,sum(o
摘要由CSDN通过智能技术生成

一、 选择题(每题3分,满分30分)

  1. 列出客户订单总金额大于3000的数据,正确的是( )

    A. select C_ID,sum(orderAmount) from t_orders group by C_ID having sum(orderAmount)>3000;

    B. select C_ID,sum(orderAmount) from t_orders where sum(orderAmount)>3000 group by C_ID;

    C. select C_ID,sum(orderAmount) from t_orders where sum(orderAmount)>3000;

    D. select C_ID,sum(orderAmount) from t_orders group by C_ID where sum(orderAmount)>3000;

    解析:A

    where只能把当前表中存在的列作为查询条件

    having 二次过滤 将一次查询产生的结果表中存在的列作为条件

  2. 模糊查询( ),可以检索出以“M”开头,且第二个字符不是“c”的所有字符串

    A.  like ‘Mc_’
    
    B.  like ‘Mc%’
    
    C.  like ‘M[^c]_’
    
    D.  like ‘M[^c]%

    解析:D

    模糊查询-----搜索框

    语法:like 支持正则

    demo:‘花里胡哨的猛男’

    • %匹配任意长度的任意字符 :like demo ‘花%’ like demo ‘%花’ like demo ‘%花%猛%’

    • _匹配一个任意字符:like demo ‘花-’ like demo ‘-花’ like demo ‘-花-猛-’ 【限制字符串长度】

    • [ ]匹配[ ]中的任一字符:like name ‘[大小黑灰]白’ :大白、小白、黑白、灰白

    • [^ ]匹配除[ ]中的任一字符:

      like name ‘[^大小黑灰]白’    除【大白、小白、黑白、灰白】之外的任一情况
      
  3. 在SQL查询时,使用( )子句可以指定分组

    A. where

    B. having

    C. when

    D. group

    解析:D

  4. replace函数的作用是( )

    A. 字符串替换

    B. 取最大值

    C. 取最小值

    D. 获取当前时间

    解析:A

  5. 描述年龄20到25之间正确的表达式是( )

    A. between 20 to 25

    B. between 20 and 25

    C. no between 20 to 25

    D. no between 20 and 25

    解析:B

  6. 查询t_student表中所有非空email信息,以下语句正确的是( )

    A. select email from t_student where email != null;

    B. select email from t_student where email not is null;

    C. select email from t_student where email <> null;

    D. select email from t_student where email is not null;

    解析:D

    在mysql中 = != 判空无效,判空用 is null is not null

    <> :不等于 select * from t_account where balance<>name;

    <=> 【左右两边的字段的值相等或者都是Null 返回true】:

    select * from t_student where id <=> age; 返回满足条件的数据记录,如果没有满足条件的数据,则返回空表

  7. 定义金额,适宜使用的类型为( )

    A. int

    B. real

    C. varchar(30)

    D. double

    解析:D

    tinyint小整型 -128-127

    int/Integer大整型 :age int(2) 【实体类 封装 private Integer Double】

    float单精度

    double双精度

    decimal精确度:字段 money decimal(5,2) 5是数字总长度 2 是小数部分长度 999.99

  8. 定义列中可以接受的数据值或格式,称为( )

    A. 唯一性约束

    B. 检查约束

    C. 主键约束

    D. 默认约束

    解析:B

    数据库:-----数据库软件

    • 关系型:行表:oracle sql server mysql DB2 sybase

    • 非关系型:key-value : redis mongoDB memcache

    数据库服务:mysql mysql 57

    库:一对多

    表:一对多 行和列

    sql—高级语言 — 大部分数据库软件使用语法基本相同 部分语法不同、支持不同

    sql六大约束:

    • not null 非空

    • unique 唯一

    • primary key 主键

    • foreign key 外键

    • check 检查 mysql不提供支持、使用无效 sex varchar(3) check in(‘男’,‘女’) 男女左右AB

    • default 默认

    非标准约束:unsigned 无符号 ,只限制整型,不能修饰主键

  9. 从产品表t_products中查询单价unitprice在6-10的产品名称和单价信息,正确的SQL是( )

    A. select name,unitprice from t_products where unitprice between 6 and 11;

    B. select name,unitprice from t_products where unitprice between 10 and 6;

    C. select name,unitprice from t_products where unitprice in(6,10);

    D. select name,unitprice from t_products where unitprice >= 6 and unitprice <= 10;

    解析:D

  10. 删除一张表的语法是( )

    A. delete from…

    B. drop table…

    C. create table…

    D. remove…

    解析:B

    CRUD: create  read   update   delete
    表:
    drop table   表名;# 删表
    # 修改表(添加列、添加约束)
    alter  table  表名   add  id  int ;
    alter table 表名   add  constraint   
    
    

二、 代码题(满分70分)

  1. 根据下面表结构,完成建库建表数据填充操作(15分)

男生信息表t_boy

字段说明 字段名称 字段类型 数据长度 主键 允空 备注
男生编号 boyId int 4 自增
性别 gender varchar 3 默认值:男
姓名 name varchar 20
年龄 age int 2
心动女生编号 girlId int 外键列

女生信息表t_girl

字段说明 字段名称 字段类型 数据长度 主键 允空 备注
女生编号 girlId int 4 自增
性别 gender varchar 3 默认值:女
姓名 name varchar 20
年龄 age int 2
心动男生编号 boyId int 外键列
create table if not EXISTS t_boy(
boyId int(4) primary key auto_increment comment '男生编号',
gender varchar(3) default '男' comment'性别',
name varchar(20) comment'姓名',
age int(2) comment'年龄',
girlId int(4) comment'外键列'  #
)engine=InnoDB default charset=utf8;

# mysql 4大引擎,只有InnoDB支持外键和事务
# 外键:表中的某一字段的值,引用另一张表中的某个字段的值。
# A表中的cloumn   B表中的Cloumn   
#  引用列            参照列(被引用列)
#  1.数据类型、约束一致   2. 被引用的数据,B表中必须存在

#   子表           父表
# 建表:先建父表,再建子表
# 删表:先删子表,再删父表</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值