100分求一查询语句!
col001 col002 col003 col004
001 skklsl 25.00 2005-12-31
001 skklsl 25.00 2005-12-31
003 iiiii 18.00 2004-05-06
002 sssss 12.00 2005-05-06
003 iiiii 18.00 2004-05-06
004 ppppp 2.30 2003-05-06
001 skklsl 25.00 2005-12-31
003 iiiii 18.00 2004-05-06
求一查询语句,得到如下结果:
col001 col002 col003 col004
001 skklsl 25.00 2005-12-31
002 sssss 12.00 2005-05-06
003 iiiii 18.00 2004-05-06
004 ppppp 2.30 2003-05-06
问题点数:100、回复次数:19Top
1 楼zhouhaihe()回复于 2006-03-03 13:45:08 得分 0
select DISTINCT * from tableTop
2 楼REDHOTSUN(路禄"QQ:243335394")回复于 2006-03-03 13:45:23 得分 0
SELECT DISTINCT * FROM TABLENAMETop
3 楼lsqkeke(可可)回复于 2006-03-03 13:46:25 得分 0
select distinct * from tablenameTop
4 楼lsqkeke(可可)回复于 2006-03-03 13:47:26 得分 0
或者:
select * from 表名 group by col001,col002,col003,col004Top
5 楼zhouhaihe()回复于 2006-03-03 13:47:53 得分 0
select col001,col002,col003,col004
from table
group by col001,col002,col003,col004
order by col001Top
6 楼wgsasd311(自强不息)回复于 2006-03-03 13:59:48 得分 0
select DISTINCT * from tb
--or
select col001,col002,col003,col004
from tb
group by col001,col002,col003,col004
Top
7 楼happyflystone(无枪的狙击手)回复于 2006-03-03 14:07:56 得分 0
要是记录全完一样,
select distinct * from table
要是col4日期不一样
select *
from table a
where not exists(select 1 from table where col1 = a.col1 and col2= a.col2 and col3 = a.col3 and col4 > a.col4)Top
8 楼mislrb(上班看看早报,上上CSDN,下班看看电影)回复于 2006-03-03 14:28:50 得分 0
都对,Top
9 楼geniusli(纠级天使)回复于 2006-03-03 14:51:03 得分 0
才不是都对,试了没呀?写
select DISTINCT * from table
都是错的Top
10 楼qyflaoda(戒骄戒躁)回复于 2006-03-03 15:00:51 得分 0
去掉重复的,然后排序,如此而已Top
11 楼biqiaqiu(比卡丘索普)回复于 2006-03-03 15:24:37 得分 0
错在哪里?Top
12 楼geniusli(纠级天使)回复于 2006-03-03 15:27:57 得分 0
CREATE TABLE [t1] (
[col001] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[col002] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col003] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[col004] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
insert into t1 values('a','1','1','1')
insert into t1 values('a','1','1','2')
insert into t1 values('b','2','2','5')
insert into t1 values('c','3','3','1')
insert into t1 values('b','2','2','2')
SELECT col001, col002, col003,
(SELECT col004
FROM dbo.t1
WHERE out.col001 = col001 AND out.col004 < col004) AS in004
FROM dbo.t1 out
WHERE ((SELECT col004
FROM dbo.t1
WHERE out.col001 = col001 AND out.col004 < col004) IS NOT NULL)
Top
13 楼geniusli(纠级天使)回复于 2006-03-03 15:31:13 得分 0
日期不同的话,只用distinct就不行了Top
14 楼biqiaqiu(比卡丘索普)回复于 2006-03-03 15:35:41 得分 0
按照搂住设计的表为什么不能更新表中数据呢?Top
15 楼biqiaqiu(比卡丘索普)回复于 2006-03-03 15:43:19 得分 0
WHERE out.col001 = col001 AND out.col004 < col004) AS in004
解释一下这句代码可以吗?Top
16 楼nick_nie()回复于 2006-03-03 15:45:02 得分 0
select distinct * from tablename
关键时 distinctTop
17 楼biqiaqiu(比卡丘索普)回复于 2006-03-03 15:49:59 得分 0
要是记录全完一样,
select distinct * from table
要是col4日期不一样
select *
from table a
where not exists(select 1 from table where col1 = a.col1 and col2= a.col2 and col3 = a.col3 and col4 > a.col4)
请问 select 语句中 1代表什么?Top
18 楼dandanyiwang(tuifei)回复于 2006-03-04 16:27:30 得分 0
TO:biqiaqiu(比卡丘索普)
请问 select 语句中 1代表什么?
這個1也可以换成*号Top
19 楼net_morning(矿泉水)回复于 2006-03-04 16:45:33 得分 0
SELECT DISTINCT ( col001,col002,col003) FROM TABLENAMETop




