排序,去重,分組,作業

2022-08-15 07:06:10 字數 4073 閱讀 3800

all:所有的意思

in:代表在某些引數範圍之內的都符合條件【in()】括號裡面寫引數,相當於多個or

select *from 檔名 where 表名 in ()

not:起到修飾的作用,取反,寫在in前面

select *from 檔名 where 表名 not in ()

between and 表示在某個範圍之內,相當於》= <=

select *from 檔名 where ids>500 and ids<505

select *from 檔名 where ids between 500 and 505

模糊查詢,行業裡面帶國家兩個字

select *from 檔名 where name like'%國家%'

select *from 檔名 where name like'國家'

select *from 檔名 where name like'%機構'

select *from 檔名 where name not like'%國家%'

select *from 檔名 where ids > all

(select ids from 檔名 where ids >1190 and ids <1995

)any:大於小的,小於大的(大於裡面的乙個)

查出一列來當做引數來使用

怎麼排序

--select *from 檔名 order by ids表裡面的列

asc:公升序的意思

desc:從大往小排

對兩列進行排序

select *from 檔名 order by parent,ids

parent,ids:為列名

分組:把一列裡面相同的分為一組

select  列名 from 檔名 group by 列名

select code from 檔名 where parent='m'

去重select distinct parent from category

前多少條資料

select top 5 *from category

select top 5 *from category order by ids

select top 5 *from dategory where ids>900 and ids<950 order by ids

--學生資訊表

--學號,姓名,班級,性別,教師,出生日期,身高

新增20條虛擬資料

查詢男同學身高170以上的

查詢姓王的同學資訊

查詢一共有幾個班級

查詢女同學裡身高在168,170,172折三個數的資訊

create table xueshengxinxibiao

(  xuehao int,

name  varchar(50),

class varchar(50),

xingbie varchar(50),

jiaoshi varchar(50),

chushengriqi varchar(50),

shengao varchar(50)

)insert into xueshengxinxibiao values(1,'喬峰','一年級一班','男','天龍','1988-03-14','181cm')

insert into xueshengxinxibiao values(2,'阿朱','一年級一班','女','天龍','1988-04-05','168cm')

insert into xueshengxinxibiao values(3,'段譽','一年級一班','男','天龍','1988-12-09','178cm')

insert into xueshengxinxibiao values(4,'王語嫣','一年級一班','女','天龍','1988-05-06','173cm')

insert into xueshengxinxibiao values(5,'虛竹','一年級一班','男','天龍','1988-06-04','178cm')

insert into xueshengxinxibiao values(6,'夢姑','一年級一班','女','天龍','1988-07-19','172cm')

insert into xueshengxinxibiao values(7,'慕容復','一年級一班','男','天龍','1988-12-18','175cm')

insert into xueshengxinxibiao values(8,'阿碧','一年級一班','女','天龍','1988-09-01','165cm')

insert into xueshengxinxibiao values(9,'王夫人','一年級一班','女','天龍','1988-08-08','165cm')

insert into xueshengxinxibiao values(10,'鍾靈','一年級一班','女','天龍','1988-06-01','160cm')

insert into xueshengxinxibiao values(11,'段正淳','一年級一班','男','天龍','1988-03-04','176cm')

insert into xueshengxinxibiao values(12,'楊過','一年級二班','男','神鵰','1988-10-01','180cm')

insert into xueshengxinxibiao values(13,'時遷','一年級三班','男','水滸','1988-09-25','170cm')

insert into xueshengxinxibiao values(14,'宋江','一年級三班','男','水滸','1988-05-23','173cm')

insert into xueshengxinxibiao values(15,'林沖','一年級三班','男','水滸','1988-11-11','183cm')

insert into xueshengxinxibiao values(16,'孫二娘','一年級三班','女','水滸','1988-02-18','174cm')

insert into xueshengxinxibiao values(17,'小龍女','一年級二班','女','神鵰','1988-06-19','168cm')

insert into xueshengxinxibiao values(18,'王蓉','一年級二班','女','神鵰','1988-08-23','165cm')

insert into xueshengxinxibiao values(19,'郭靖','一年級二班','男','神鵰','1988-08-13','175cm')

insert into xueshengxinxibiao values(20,'洪七公','一年級二班','男','神鵰','1988-08-29','170cm')

select *from xueshengxinxibiao

select *from xueshengxinxibiao where xingbie='男'and shengao > '170cm'

select *from xueshengxinxibiao where name like '%王%'

select class from xueshengxinxibiao group by class

select *from xueshengxinxibiao where xingbie='女'and (shengao ='168cm'or shengao='170cm'or shengao='172cm')

--查男同學的身高高於所有女同學的同學資訊

select top 3 *from xueshengxinxibiao where shengao not in (select top 5 shengao from xueshengxinxibiao order by shengao desc,xuehao desc) order by shengao desc

--查男同學的身高高於所有女同學的同學資訊

select *from xueshengxinxibiao where xingbie='男' and shengao>all(select shengao from xueshengxinxibiao where xingbie='女')

A 排序去重

有n 個1 到 1000 之間的整數 對於其中重複的數字,只保留乙個,把其餘相同的數去掉。然後再按照指定的排序方式把這些數排序。第 1 行為字母 a 或 d,a 表示按照公升序排序,d 表示按照降序排序。第 2 行開始有若干個用乙個空格或換行符分隔的正整數。相互之間用乙個空格分隔的經去重和排序後的正...

SQL指令碼去重分組統計

需求 首先有一張表記錄學生姓名 科目和成績,然後模擬插入幾條資料,指令碼如下 create table score name nvarchar 20 姓名 subject varchar 20 科目 grade int 成績 insert into score name,subject,grade ...

Oracle Oracle去重分組拼接字串

要實現的是去重按順序分組拼接字段,且輸出表中需要拼接多個字段。1 查了網上大概有四種方法,各有特點 1 wmsys.wm concat column 2 listagg column,within group order by over partition by 3 sys connect by p...