日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

查询题 周末

發布時間:2023/12/18 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 查询题 周末 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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
)

?

轉載于:https://www.cnblogs.com/xiaoluoboer/p/8025366.html

總結

以上是生活随笔為你收集整理的查询题 周末的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。