[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>select 语句查询格式
select 目标表的列名或列表达式序列(2019-ave)
from 基本表名 (最好加一个别名容易操作)和(或)视图序列
[where 行条件表达式]
[group by 列名序列
[having 组条件表达式]]
[order by 列名[asc(升序)| desc(降序)]…]
*
子句select-from-where的执行过程 :
根据where子句的条件表达式,从from表中指定的表或视图中找到满足条件的元组,再按照select子句中的目标列表达式再选出元组中的属性形成结果表。
*
整个子句的执行过程 :
读取from子句中的基本表,视图,进行笛卡尔积操作——>选取满足where子句中条件表达式的元组——>按照group子句里面的指定列进行分组,提取满足having子句条件的表达式的组——>按select给出的列名或列表达式求值取出——>根据order
by对输出表进行排序,升序或降序。
<>表的查询
单表查询(最简单的查询)
// 1.查询指定列 select SNO, SNAME from s; //2.查询全部列(两种方法) select * from s;
/**列名非常的多时推荐使用**/ select sno, sname, sex, avg, sdept from s;
/**列的显示顺序与基表的顺序相同**/ //3.查询经过计算的列 //比如:查询全体学生的姓名及出生年份 select sname, 2019 - ave
from s; //4.选择表中的若干行 /**distinct消除重复行,默认是all**/ select distinct sno from sc;
/**用in查找指定集合的元组**/ //比如:查询计算机系(CS),数学系(MA), 信息系(IS)学生的姓名和性别 select sname, sex
from s where sdept in ('CS', 'MA', 'IS'); //5.涉及到空值的查询(只能用is不能用=) select sno,cno
from sc where grade is null; select sno,cno from sc where grade is not null;
//6.多重条件:可用逻辑运算符AND和OR来连接多个查询条件,AND的优先级高于OR,括号可以改变优先级 select sno,cno from sc
where sdeptin ('CS', 'MA', 'IS') and grade is not null; //7.order
by子句:按一个或多个属性列排序。升序:ASC;降序:DESC;默认是升序 select sno,cno from sc order by grade desc
; * 当排序含空值时:ASC:排序列为空值的元组最后显示;DESC:排序列为空值的元组最先显示