简体   繁体   English

sql合并相同主键的行

[英]sql combining rows of the same primary key

In here you can see the nested or statement which allows me to combine the answers.text and answers.integer to the same table in some order 在这里,您可以看到嵌套或语句,该语句使我可以按顺序将Answers.text和answers.integer组合到同一张表中

But what I would like to do is have the integers and text on the same row if they have the same submission id. 但是我想做的是,如果整数和文本具有相同的提交ID,则它们在同一行上。 How would I do that? 我该怎么做?

EDIT: The concat was supposed to combine the two on the same line, or so I thought. 编辑:concat应该在同一行上将两者结合在一起,所以我想。 But it had just took out the nulls from the columns so that there were only two -> submissions and building_idquant. 但是它只是从列中删除了空值,因此只有两个->提交和building_idquant。 When before there was submission_id, building_id, and integer. 之前的时间是submission_id,building_id和整数。

its tough to get your expectation from image but i thought after seeing your image you need below somethin 很难从图像中获得您的期望,但我想在看到您的图像之后,您需要一点东西

select submission_id,building_idquant ,
    concat(CONVERT(varchar(50), submission_id),building_idquant ) as id_quant from
    (
    select distinct submission_id,building_idquant from tablename 
    ) t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM