举个例子
表:
productid color size productname
----------------------------------------------
100001 B L 黑色大号鞋
100001 W S 白色小号鞋
100002 W L 白色大号袜子
... ... ... ...
----------------------------------------------这样的数据,我想检索出商品的数据,但同一个商品只要一条记录如:
productid color size productname
----------------------------------------------
100001 B L 黑色大号鞋
100002 W L 白色大号袜子如何写sql语句才能做到?主要是如何做到相同的productid只取一条记录?
表:
productid color size productname
----------------------------------------------
100001 B L 黑色大号鞋
100001 W S 白色小号鞋
100002 W L 白色大号袜子
... ... ... ...
----------------------------------------------这样的数据,我想检索出商品的数据,但同一个商品只要一条记录如:
productid color size productname
----------------------------------------------
100001 B L 黑色大号鞋
100002 W L 白色大号袜子如何写sql语句才能做到?主要是如何做到相同的productid只取一条记录?
解决方案 »
- 报错ORA-01652:无法通过128(在表空间TEMP)扩展TEMP段
- oracle基础
- 不显示删除回复显示所有回复显示星级回复显示得分回复 页面加密传输密码
- 在WindowsXp Pro下安装Oracle11g无法创建数据库
- 利用oracle自带的database config assiant新建数据库很大,有900M,我想建立一个空的数据库如何处理阿
- 怎么无法向CLOB中插入大数据,急急!!!!在线等
- 心情不好,散分!!!!!
- 请问为什么create table bbb as select * from aaa ,aaa上面的缺省值还有索引都掉了呢?
- 1、ORACLE的不完全恢复?2、connect test/test as sysdba?
- oracle安装后sql server连接不上
- 请教高手, 这个 sql 怎么写?
- 如何修改ORACLE的唯一索引
t.*
from
表 t
where
not exists(select
*
from
表
where
productid=t.productid
and
productname>t.productname)
第1行 a 9 5
第2行 b 8 5
第3行 c 7 6
第4行 d 6 6
第5行 e 5 7
--@Test
declare @test table(c1 varchar(1),c2 int,type int)
insert @test
select 'a',9,5 union all
select 'b',8,5 union all
select 'c',7,6 union all
select 'd',6,6 union all
select 'e',5,7--按记录顺序取第一条
select * from @test a where c1=(select top 1 c1 from @Test where type=a.type)--取最小
select * from @test a where c1=(select min(c1) from @Test where type=a.type)--取最大
select * from @test a where c1=(select max(c1) from @Test where type=a.type)--随机取
select * from @test a where c1=(select top 1 c1 from @Test where type=a.type order by newid())
--按记录顺序取第一条
select * from @test a where c1=(select c1 from @Test where type=a.type and rownum = 1)
那么
--随机取
select * from @test a where c1=(select top 1 c1 from @Test where type=a.type order by newid())
改成rownum 的方式,怎么加order by 啊,呵呵,小弟在这方面学识浅薄阿,还请指点
很复杂〉?select distinct id,color,size
from t;