一个SQL 查询难题 select * from tb a where not exists(select 1 from tb where 单据号=a.单据号 and 条码=a.条码 and 日期>a.日期) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个问题出现很多次了 sdhdy帮忙总结下 解释下 if object_id('[tb]') is not null drop table [tb] gocreate table tb([单据号] varchar(20),[日期] varchar(10),[条码] varchar(10),[进价/付款] varchar(10),[别] varchar(10),[序号] varchar(10))insert tb select 'SD200901011','2009-04-10','A0001',190,1,1insert tb select 'SD200901011','2009-04-10','A0001',192,2,2insert tb select 'SD200901011','2009-04-10','A0002',193,1,4insert tb select 'SD200901011','2009-04-10','A0002',194,1,5insert tb select 'SD200901013','2009-04-12','A0001',190,1,1insert tb select 'SD200901013','2009-04-12','A0001',192,2,2insert tb select 'SD200901013','2009-04-12','A0002',193,1,4insert tb select 'SD200901013','2009-04-12','A0002',194,1,5select * from tb a where not exists(select 1 from tb where 条码=a.条码 and 日期>a.日期 or (条码=a.条码 and [进价/付款]>a.[进价/付款]))/*单据号 日期 条码 进价/付款 别 序号-------------------- ---------- ---------- ---------- ---------- ----------SD200901013 2009-04-12 A0001 192 2 2SD200901013 2009-04-12 A0002 194 1 5(2 行受影响)*/ 无法访问sql数据库 读取两张表,并存入临时表的问题,请教大家! sql2000中用sql语句给新建用户查询某一数据库全部表的权限怎么做? 重来。。。。。。。。。。。。。。 sql语句求教 数据库出现 suspect 是什么原因? 关于数据恢复的问题! ora-03113:通信通道的文件结束 ----30分 请大虾帮忙解决两个SQL的select查询问题 mssql 数据库不能远程连接。活动端口关闭不掉什么回事? 数据库搬家 (sqlserver ==》 mysql) 疑问…… 一个关于sqlserver +php分组查询的问题
sdhdy帮忙总结下 解释下
go
create table tb([单据号] varchar(20),[日期] varchar(10),[条码] varchar(10),[进价/付款] varchar(10),[别] varchar(10),[序号] varchar(10))
insert tb select 'SD200901011','2009-04-10','A0001',190,1,1
insert tb select 'SD200901011','2009-04-10','A0001',192,2,2
insert tb select 'SD200901011','2009-04-10','A0002',193,1,4
insert tb select 'SD200901011','2009-04-10','A0002',194,1,5
insert tb select 'SD200901013','2009-04-12','A0001',190,1,1
insert tb select 'SD200901013','2009-04-12','A0001',192,2,2
insert tb select 'SD200901013','2009-04-12','A0002',193,1,4
insert tb select 'SD200901013','2009-04-12','A0002',194,1,5
select * from tb a where not exists(select 1 from tb where 条码=a.条码 and 日期>a.日期 or (条码=a.条码 and [进价/付款]>a.[进价/付款]))
/*
单据号 日期 条码 进价/付款 别 序号
-------------------- ---------- ---------- ---------- ---------- ----------
SD200901013 2009-04-12 A0001 192 2 2
SD200901013 2009-04-12 A0002 194 1 5(2 行受影响)
*/