我可以采用一组不同的 COALESCE 数据吗?
我有以下代码,到目前为止它有效:
SELECT
[id],
COALESCE ([Company], [LastName] + ', ' + [FirstName]) as Customer
FROM [some_database].[dbo].[some_table]
ORDER BY Customer
但是,我想使用 DISTINCT 关键字来消除重复的“客户”条目。这可能吗?我尝试了几种不同的方法,但没有效果。
I have the following bit of code, and it works so far:
SELECT
[id],
COALESCE ([Company], [LastName] + ', ' + [FirstName]) as Customer
FROM [some_database].[dbo].[some_table]
ORDER BY Customer
However, I'd like to use the DISTINCT keyword to eliminate duplicate "Customer" entries. Is this possible? I've tried it a few different ways, but to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有多个同名的客户条目,您必须为给定名称选择一个 ID。以下是选择最近创建的(即
max()
)的示例,但您可能想要第一个创建的(即min()
):已编辑:< /strong> 抱歉... GROUP BY 2,而不是 1
If you have multiple customer entries with the same name, you have to pick one ID for a given name. Here's an example of picking the most recently created (ie
max()
), but you may want the first created (iemin()
):EDITED: Sorry... GROUP BY 2, not 1