回复 10楼 y12692189
跟上面的数据差不多吧如果VFP的表不用SQL语句也可以,建立一个userid关联表,从最后往前扫描一次就可以。
Create TABLE A (userid CHAR(6),pcharge numeric(9,2),createtime datetime) INSERT INTO A VALUES('000001',10.21,'2001-01-01 12:00') INSERT INTO A VALUES('000001',10.21,'2001-06-15 08:01') INSERT INTO A VALUES('000002',10.21,'2011-07-17 05:00') INSERT INTO A VALUES('000003',10.21,'2021-01-27 03:00') INSERT INTO A VALUES('000001',10.21,'2002-03-13 02:00') INSERT INTO A VALUES('000004',10.21,'2008-05-05 16:00') INSERT INTO A VALUES('000005',10.21,'2009-03-04 17:00') INSERT INTO A VALUES('000066',10.21,'2017-05-08 14:00') INSERT INTO A VALUES('000003',10.21,'2023-09-03 13:00') INSERT INTO A VALUES('000002',10.21,'2020-08-06 18:00') INSERT INTO A VALUES('000001',10.21,'2001-06-15 08:02') INSERT INTO A VALUES('000002',10.21,'2000-05-09 04:00') INSERT INTO A VALUES('000001',10.21,'2002-03-06 17:00') Go Select a.* From A a, (Select UserId, Max(CreateTime) As CreateTime From A Group By UserId) t Where a.CreateTime = t.CreateTime Order By a.UserId
[此贴子已经被作者于2023-3-26 15:15编辑过]
Create TABLE A (userid CHAR(6),pcharge numeric(9,2),createtime datetime) INSERT INTO A VALUES('000001',10.21,'2001-01-01 12:00') INSERT INTO A VALUES('000001',10.21,'2001-06-15 08:01') INSERT INTO A VALUES('000002',10.21,'2011-07-17 05:00') INSERT INTO A VALUES('000003',10.21,'2021-01-27 03:00') INSERT INTO A VALUES('000001',10.21,'2002-03-13 02:00') INSERT INTO A VALUES('000004',10.21,'2008-05-05 16:00') INSERT INTO A VALUES('000005',10.21,'2009-03-04 17:00') INSERT INTO A VALUES('000006',10.21,'2017-05-08 14:00') INSERT INTO A VALUES('000003',10.21,'2023-09-03 13:00') INSERT INTO A VALUES('000002',10.21,'2020-08-06 18:00') INSERT INTO A VALUES('000001',10.21,'2001-06-15 08:02') INSERT INTO A VALUES('000002',10.21,'2000-05-09 04:00') INSERT INTO A VALUES('000001',10.21,'2002-03-06 17:00') Create TABLE B (userid CHAR(6),pwprtype char(5),) INSERT INTO B VALUES('000001','DJ1') INSERT INTO B VALUES('000002','DJ5') INSERT INTO B VALUES('000003','DJ1') INSERT INTO B VALUES('000004','DJ2') INSERT INTO B VALUES('000005','DJ5') INSERT INTO B VALUES('000006','DJ1') INSERT INTO B VALUES('000007','DJ2') INSERT INTO B VALUES('000008','DJ5') INSERT INTO B VALUES('000009','DJ5')
Select b.* From B b Left Join ( Select a.* From A a, (Select UserId, Max(CreateTime) As CreateTime From A Group By UserId) t Where a.CreateTime = t.CreateTime ) t On b.UserId = t.UserId Where t.UserId Is Null
Select b.* From B b Where b.UserId Not In (Select t.UserId From A t Where b.userid = t.UserId) Select b.* From B b Where Not Exists(Select t.UserId From A t Where b.userid = t.UserId)
[此贴子已经被作者于2023-3-26 16:22编辑过]