区别在内部子查询中不起作用 [英] Distinct is not work in inner subquery

查看:68
本文介绍了区别在内部子查询中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有这些数据
ID客户ID贷项
1 3 444
2 3 33
3 3 555
4 5 666
5 5 999
6 5 88

我想要ID = 6,3的数据是所有客户的最后一条记录.
在内部子查询中无法正常工作,该怎么办?

它的Sql Server 2005查询是什么?
[edit]别喊!它无助于您得到答案,并且使某些人烦恼.大喊大叫的标题和大喊大叫的文本已更改-OriginalGriff [/edit]

解决方案

如果您在任何客户的最后输入记录之后,则必须包含DateTime列在表格中-然后可以对它和CustomerID进行排序.
如果ID是自动递增的,则可以使用该ID(我认为是记录ID),但是为了将来扩展,我不推荐使用.

我会(可能)使用GUID而不是int作为记录ID,并添加一个DateTime列,以便您可以更好地对其进行跟踪.


请问您可以发布查询吗?

I have these data in database
Id CustomerID credit
1 3 444
2 3 33
3 3 555
4 5 666
5 5 999
6 5 88

I want data of ID=6,3 those are the last record for any customer.
Distinct is not work in inner subquery, what can I do?

What is its Sql server 2005 query?
[edit]Don''t SHOUT! It doesn''t help you get an answer, and it annoys some people. Shouty title and shouty text changed - OriginalGriff[/edit]

解决方案

If you are after the last entered record for any customer, then you will have to include a DateTime column in your table - you can then sort on that and the CustomerID.
It may be possible to use the ID (which I assume is a record ID) if it is auto increment, but for the sake of future expansion, I can''t recommend it.

I would (probably) use a GUID rather than an int for the record ID, and add a DateTime column so that you can track it better.


Can you please post the query?


这篇关于区别在内部子查询中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆