sql2005 联合查询 取表2重复纪录第1条?立帖 t1date id2008-02-26 09:46:37.737 139 460002008-02-26 20:22:28.357 139 46000t2id 46000结果2008-02-26 09:46:37.737 139 46000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select min(a.date),a.id from t1 a left join t2 b on a.id=b.id group by a.id 忘了说表1 还有其他列,ms,cell,op_date group by 会提示因为该列没有包含在聚合函数或 GROUP BY 子句中。 select a.* from t1 a left join t2 b on a.id=b.id where not exists (select 1 from t1 where date>a.date) 实际开发中也碰到此需求,直接的简单的sql语句不行 上面那个是去最大的时间下面这个是取最小的时间 select a.* from t1 a left join t2 b on a.id=b.id where not exists (select 1 from t1 where date<a.date) select *from ta awhere not exists(select 1 from ta where id = a.id and date > a.date) 谢谢大家,尤其小虫,枪手!不过我按狙击手(11),做了。distinct 后还是有很少条重复的记录不过没大碍。道理还是不很清楚 如何判断表中的某个字段必须包含三个值,都包含count就加1。。。求高手帮助! SQL 关于数据库的安装问题,请高手赐教,我在线等候回音。 高手请进,sql server 成批更新 大在线等:家有没有遇到在查询分析器中输入不了命令语句啊,急的要死? 数据库高手帮帮我! 我的小妹的vfp作业,我也不大会啊,那位行行好,做来给我,百分送出 数值比较问题!很简单,送分 数据库表与表之间的关联问题。。。急。。 触发器中如何得到自己所在表的表名以及触发器名这两个变量? 关于时间(续) 求一sql语句!!
select min(a.date),a.id from t1 a left join t2 b on a.id=b.id group by a.id
下面这个是取最小的时间
select a.* from t1 a left join t2 b on a.id=b.id where not exists (select 1 from t1 where date<a.date)
from ta a
where not exists(select 1 from ta where id = a.id and date > a.date)
不过没大碍。道理还是不很清楚