• 查询题 周末


    1.创建留言数据库: liuyandb;
    create database liuyandb;

    2.在liuyandb数据库中创建留言表liuyan,
    create table liuyan(
    id int auto_increment primary key comment '编号',
    title varchar(32) not null comment '标题',
    author varchar(16) null comment '作者',
    addtime varchar(12) not null comment '留言时间',
    content text not null comment '留言内容',
    isdelete tinyint not null default 0 comment '是否删除'
    )engine=innodb default charset=utf8;


    注意: comment :表示注释

    3.在留言表最后添加一列状态(status tinyint 默认值为0),???

    alter table liuyan add status tinyint default 0 after isdelete;

    注意:after isdelete:表示在哪个字段后添加 新字段


    4.修改留言表author的默认值为’youku’,设为非空
    alter table liuyan modify author varchar(16) not null default 'youku';

    5.删除liuyan表中的isdelete字段
    alter table liuyan drop isdelete;

    6.为留言表添加>5条测试数据

    insert into liuyan values
    (null,'介绍','大雄','1000','哥不是一匹好马,但也不是一头普通的毛驴',null),
    (null,'叮当猫','熊熊','2000','你牙缝里有韭菜,扣出来贼哥吃',null),
    (null,'花花','苗苗','3000','苗苗问花花:卖萌是褒义词还是贬义词?',null),
    (null,'霞哥','雄大','4000','斗战色佛',null),
    (null,'晨晨','逗比','5000','你笑起来像一朵菊花,菊花残,man腚伤',null);

    7.要求将id值大于3的信息中author字段值改为admin
    update liuyan set author='admin' where id>3;

    8.删除id号为4的数据
    delete from liuyan where id=4;

    附加题:

    9.为留言表添加>15条测试数据,要求分三个用户添加

    懒.....

    10.查询所有留言信息
    select id,title,author,addtime,content,status from liuyan;

    11.查询某一用户的留言信息
    select id,title,author,addtime,content,status from liuyan where author='用户名称';

    12.查询所有数据,按时间降序排序
    select id,title,author,addtime,content,status from liuyan order by addtime desc;

    13.获取id在2到6之间的留言信息,并按时间降序排序
    select id,title,author,addtime,content,status from liuyan where id between 2 and 6;

    14.统计每个用户留了多少条留言,并对数量按从小到大排序。
    select author,count(id) as'留言条数' from liuyan group by author order by count(id) desc

    15.将id为8、9的两条数据的作者改为’doudou’.
    update liuyan set author ='doudou' where id in(8,9);

    16.取出最新的三条留言。(使用limit)。
    select * from ( select id,title,author,addtime,content,status from liuyan ORDER BY addtime desc)hahg LIMIT 3


    17.查询留言者中包含”d”字母的留言信息,并按留言时间从小到大排序
    select id,title,author,addtime,content,status from liuyan where author like'%d%' order by addtime asc;

    18.删除”作者”重复的数据,并保留id最大的一个作者
    delete from liuyan where author in(
    select author from (select author from liuyan group by author having count(1)>1) a
    )
    and id not in(
    select id from (select max(id) id from liuyan group by author having count(1)>1) b
    )

  • 相关阅读:
    maven导入项目时出现“Cannot read lifecycle mapping metadata …… invalid END header (bad central directory offset)pom”错误的解决方法
    Eclipse下使用Git
    Sprint Boot入门(1):创建第一个Spring Boot应用
    Gradle入门(6):创建Web应用项目
    Gradle入门(5):创建二进制发布版本
    maven在windows10系统下安装配置和打包war
    Windows10系统下安装配置Tomcat 9.0.1
    面试题1
    Json序列化帮助类
    NPOI帮助类
  • 原文地址:https://www.cnblogs.com/xiaoluoboer/p/8025366.html
Copyright © 2020-2023  润新知