--try
select T.Cid,
T.Cdate
from
(
select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
) T
Group By T.CID
Having count(T.CID)=2
order by T.Cdate desc
select T.Cid,
T.Cdate
from
(
select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
) T
Group By T.CID
Having count(T.CID)=2
order by T.Cdate desc
解决方案 »
- 在线急等,如何优化评论数据库的
- 这是我的作业,但是我不太会,哪位高手纠救救我呀,拜托了,thank you advanced!!!
- 求SQL语句
- 如何用SQL 语句,将数据库中的所有表 加一个字段!
- sql 逻辑运算符的问题
- int型转换成varchar型?
- 求sql语句
- 再次求字段为ntext类型的sql精确查询语句
- 为什么说java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。?
- 如何用sql语句使选取出的数值型字段保留两位小数
- 字符转换为计算
- 请问有没有取代not in的其他方法
c.*
from
结果集 c
where
c.Cdate in(select top 2 Cdate from 结果集 where Cid=c.Cid order by Cdate desc)
a.*
from
table a
where
a.Cdate in(select top 2 Cdate from table where Cid=a.Cid order by Cdate desc)
select T.Cid,
T.Cdate
from
(
select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
) T
where
T.Cdate in(select top 2 T1.Cdate from
(
select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
) T1
where T1.Cid=T.Cid order by T1.Cdate desc)
select
C1.*
from C C1
where EXISTS (select 1 FROM (SELECT * top 2 Cdate from C C2 where C2.Cid=C1.Cid order by Cdate desc)D WEHRE D.Cdate = C1.Cdate)
谢谢大家帮助!结贴!
create table #(Cid int,Cdate datetime)insert into #
select 1,'2005-10-1'
union all select 2,'2005-10-2'
union all select 1,'2005-10-3'
union all select 3,'2005-10-4'
union all select 1,'2005-10-5'
union all select 2,'2005-10-6'
union all select 2,'2005-10-7'select * from #--产生结果集
select
c.*
from
# c
where
c.Cdate in(select top 2 Cdate from # where Cid=c.Cid order by Cdate desc)
order by cid,cdate desc