TAB1
T_NO Goods_Code Letter_No Goods_DateTiem
1234 R P1012007 2008-01-02 10:11
1235 R P1012007 2008-01-02 10:11
1234 C P1012007 2008-01-02 12:11需要查询结果如下T_NO Goods_Code Letter_No Goods_DateTiem
1234 C P1012007 2008-01-02 12:11
1235 R P1012007 2008-01-02 10:11表中,P1012007本来有二条记录,现在我只对1234进行了处理,1235的状态还是R
T_NO Goods_Code Letter_No Goods_DateTiem
1234 R P1012007 2008-01-02 10:11
1235 R P1012007 2008-01-02 10:11
1234 C P1012007 2008-01-02 12:11需要查询结果如下T_NO Goods_Code Letter_No Goods_DateTiem
1234 C P1012007 2008-01-02 12:11
1235 R P1012007 2008-01-02 10:11表中,P1012007本来有二条记录,现在我只对1234进行了处理,1235的状态还是R
解决方案 »
- 求出批次号最大值 -----help me...
- 联合多个表(Inner Join)
- 判断null的问题
- SQL7如何升级到SQL2005??
- 求一条sql语句。将数据库中重复的记录合并为一条记录。
- Cannot create PoolableConnectionFactory
- 怎样把文件夹中hotelmanagement.mdf这样的数据库文件导入到microsoft sql server中?
- 这个sql语句怎么写?
- 动态SQL的执行问题?急啊,各位帮帮我吧
- 想在一个字段里插入有格式的文本如Doc文件!应该用什么类型的字段!急用!谢谢!
- 自定义函数执行问题
- 求一能够下载sqlsever 2005的地址
(select 1 from tab1 where goods_code=a.goods_code and t_no>a.t_no)
这样?
select * from tab1 a where not exists(select 1 from tab1 where T_NO=a.T_NO and Goods_DateTiem>a.Goods_DateTiem)
select * from tab1 a where not exists(select 1 from tab1 where T_NO=a.T_NO and Goods_DateTiem>a.Goods_DateTiem)
这样查询把Letter_No不是P1012007 的也查询出来,我加了Letter_No只有一条记录了
那这样?还不是太明白楼主的需求:
select * from tab1 a where Letter_No='P1012007' and not exists(select 1 from tab1 where Letter_No='P1012007' and T_NO=a.T_NO and Goods_DateTiem> a.Goods_DateTiem)
select * from T a where not exists(select 1 from t where Letter_No=a.Letter_No and Goods_Code=a.Goods_Code and T_NO>a.T_NO) and Letter_No='P1012007'--取某一条
LZ本意如此吧?
drop table tb
go
create table tb(T_NO int,Goods_Code varchar(1),Letter_No varchar(10),Goods_DateTiem datetime)
insert tb
select 1234,'R','P1012007','2008-01-02 10:11' union all
select 1235,'R','P1012007','2008-01-02 10:11' union all
select 1234,'C','P1012007','2008-01-02 12:11' select * from tb a
where not exists (select 1 from tb where tb.T_NO=a.T_NO and tb.Goods_DateTiem>a.Goods_DateTiem)
order by a.T_NO
select max(T_NO) from TAB1 group by Goods_Code , Letter_No , Goods_DateTiem
) order by T_NO
select max(T_NO) from TAB1 group by Goods_Code , Letter_No , Goods_DateTiem
where Letter_No = 'P1012007'
) order by T_NO
(select T_NO+max(Goods_DateTiem) from tb
group by T_NO)
]
select * from tb where T_NO+Goods_DateTiem in
(select T_NO+max(Goods_DateTiem) from tb
group by T_NO)