SQL将两行合并到一个select语句中

编程入门 行业动态 更新时间:2024-10-24 23:25:22
本文介绍了SQL将两行合并到一个select语句中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好, 我有两列我正在运行一个独特的select语句。问题是我真的只想要第一列的一个独特的,第二个我想采取非NULL的一个或两个都是NULL然后传递NULL。 我正在使用这个选择语句。

Hello, I have two columns that I am running a distinct select statement for. The problem is I really want just a distinct for the first column, the second one I would like to take the one that isn't NULL or if both are NULL then pass NULL. I am using this select statement.

SELECT DISTINCT offer_id_new ,Date1 FROM [PCGRecruitingDatabaseUpsize].[dbo].[ExtendOffer]

它还给我这个

And it returns me this

offer_id_new Date 819 2009-05-08 00:00:00.000 864 NULL 864 2010-08-08 00:00:00.000 866 NULL

对于两个ID为864的ID,我想每个offer_id_new只拉一个,但这个ID864都有一个NULL日期和约会。如果存在,我想只有一行是日期。

For the two ID's of "864", I would like to pull only one per offer_id_new but this ID "864" has both a NULL date and a date. If this exists I would like to just have 1 row which is the date.

推荐答案

你也可以尝试聚合(分组) You could also try an aggregate (group by) SELECT offer_id_new ,max(Date1) FROM [PCGRecruitingDatabaseUpsize].[dbo].[ExtendOffer] GROUP BY offer_id_new

您好, 将'左连接'改为一个'内部联接'。 干杯 Hello, Alter the 'left join' into a 'inner join'. Cheers

我想通了。插入临时表,其中Date不为null。如果临时表中不存在id,则再次插入。 I figured it out. Insert into a temp table where Date is not null. Then insert again if the id does not exist in the temp table.

更多推荐

SQL将两行合并到一个select语句中

本文发布于:2023-07-22 10:31:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1186721.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两行   语句   并到   SQL   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!