1
字段ID 姓名 科目 分数
1 A 语文 80
2 A 数学 90
3 B 语文 90
4 B 数学 90
5 C 语文 90
5 C 数学 80
找出分数都是90分的同学姓名
2 表
ID 类别 价钱 点击
1 男装 120 2
2 女装 110 9
3 女裤 220 8
4 男裤 300 5
5 女鞋 800 9
6 男鞋 700 2查询出同类别服装(男女为同类)按点击次数排序
字段ID 姓名 科目 分数
1 A 语文 80
2 A 数学 90
3 B 语文 90
4 B 数学 90
5 C 语文 90
5 C 数学 80
找出分数都是90分的同学姓名
2 表
ID 类别 价钱 点击
1 男装 120 2
2 女装 110 9
3 女裤 220 8
4 男裤 300 5
5 女鞋 800 9
6 男鞋 700 2查询出同类别服装(男女为同类)按点击次数排序
select distinct name
from ta
where 分数 = 90
ID 类别 价钱 点击
1 男装 120 2
2 女装 110 9
3 女裤 220 8
4 男裤 300 5
5 女鞋 800 9
6 男鞋 700 2 --select *
from ta
order by right(类别,1),点击 desc
select distinct Name from A where =90
2
select * from B order by 类别,点击
select distinct Name from A where =90 --2.
select * from B order by 类别,点击
select distinct name from 表1 where 分数 = 90select * from 表2 order by left(类别,1),点击
SELECT * FROM 表2 ORDER BY 点击 题如其名,纯属送分贴
insert into tb select 1,'A','语文',80
insert into tb select 2,'A','数学',90
insert into tb select 3,'B','语文',90
insert into tb select 4,'B','数学',90
insert into tb select 5,'C','语文',90
insert into tb select 6,'C','数学',80select 姓名 from tb a
where 分数=90
group by 姓名
having count(1)=(select count(1) from tb where 姓名=a.姓名)
create table ta(id int,类别 varchar(10),价钱 int,点击 int)
insert into ta select 1,'男装',120,2
insert into ta select 1,'女装',110,9
insert into ta select 1,'女裤',220,8
insert into ta select 1,'男裤',300,5
insert into ta select 1,'女鞋',800,9
insert into ta select 1,'男鞋',700,2select * from ta
order by left(类别,1),点击 1 B
21 男装 120 2
1 男鞋 700 2
1 男裤 300 5
1 女裤 220 8
1 女鞋 800 9
1 女装 110 9
1、
select distinct 姓名 from tb where not exists(select 1 from tb where 姓名 = a.姓名 and 分数<> 90)2、
select right(rtrim(类别),len(rtrim(类别))-1),sum(点击) from tb
group byright(rtrim(类别) order by sum(点击)
select distinct 姓名 from tb a where not exists(select 1 from tb where 姓名 = a.姓名 and 分数<> 90)
select right(rtrim(类别),len(rtrim(类别))-1),sum(点击) from tb
group by right(rtrim(类别),len(rtrim(类别))-1)
order by sum(点击)
2.select 类别,点击 from tablename2 group by 类别 order by 类别
if object_id('tempdb.dbo.#1') is not null drop table #1
create table #1 (ID int,姓名 varchar(1),科目 varchar(4),分数 int)
insert into #1
select 1,'A','语文',80 union all
select 2,'A','数学',90 union all
select 3,'B','语文',90 union all
select 4,'B','数学',90 union all
select 5,'C','语文',90 union all
select 6,'C','数学',80
--> 测试数据: #2
if object_id('tempdb.dbo.#2') is not null drop table #2
create table #2 (ID int,类别 varchar(4),价钱 int,点击 int)
insert into #2
select 1,'男装',120,2 union all
select 2,'女装',110,9 union all
select 3,'女裤',220,8 union all
select 4,'男裤',300,5 union all
select 5,'女鞋',800,9 union all
select 6,'男鞋',700,2--> 找出分数都是90分的同学姓名:
select 姓名 from #1 t where not exists (select 1 from #1 where 姓名=t.姓名 and 分数<>90) group by 姓名 having count(1) = 2--> 查询出同类别服装(男女为同类)按点击次数排序:
--> 这个问题描述不明确,我觉得楼主应该是要1男1女这样排,这就有点难搞,先抄上面的答案。
select * from #2 order by left(类别,1),点击 desc
select distinct 姓名 from 表 a where not exists(select * from 表 where 姓名=a.姓名 and 分数<>90)--2.
select * from 表 order by stuff(类别,1,1,''),点击 desc
字段ID 姓名 科目 分数
1 A 语文 80
2 A 数学 90
3 B 语文 90
4 B 数学 90
5 C 语文 90
5 C 数学 80
找出分数都是90分的同学姓名 select name 姓名 from stuinfo where exam=90
2 表
ID 类别 价钱 点击
1 男装 120 2
2 女装 110 9
3 女裤 220 8
4 男裤 300 5
5 女鞋 800 9
6 男鞋 700 2 查询出同类别服装(男女为同类)按点击次数排序
select type 类别 from product order by click desc --降序
是不是..男裤和女裤是一类...鞋也是....
select distinct name from 表1 where 分数 = 90select * from 表2 order by right(类别,1),点击
select distinct name from table1
group by name
having min(grade)=90
select 姓名,count(分数) from 1
where 分数='90'
group by 姓名
having count(分数)>12、
select 类别,sum(点击)from 2
group by 类别
--哈哈,给点意见啊。我还是菜鸟。
select 类别,sum(点击)as'点击'from 2
group by 类别
order by '点击'