连接两列中具有相同值的两行

编程入门 行业动态 更新时间:2024-10-25 23:36:18
本文介绍了连接两列中具有相同值的两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的桌子的打印屏幕图像.

This is printscreen image of my table.

我有一个名为table"的 MySQL 表.当我在 while 循环中编写SELECT * FROM table"时,我想获得一次相同的fikraNo"和maddeNo"值.但是如果 fikraNo 和 maddeNo 具有相同的值,则必须加入icerik".例如,当我想从表中获取所有值时,输出必须是这样的:

I have a MySQL table named "table". When I wrote "SELECT * FROM table" in the while loop, I want to get one time same values of "fikraNo" and "maddeNo". But if fikraNo and maddeNo have same value, "icerik" must be joined. For example when I want to get all values from the table, the output must be like this:

1 1 174 Lorem ipsum dolor sit amet, consectetur adipiscing... 2 2 174 1500'lerden beri kullanılan standart Lorem Ipsum... 3 3 174 Nullam mollis accumsan quam eget aliquet. Ut sit a... 4 1 135 Phasellus ac massa neque. Nunc blandit, nibh sit a... 5 2 135 Nulla id placerat odio. Fusce quis porttitor dui. ... 6 0 135 Vestibulum elit neque, ultrices ac consequat vitae... 7 1 134 Etiam dignissim, lacus sed faucibus auctor, felis ... 8 2 134 Vestibulum rhoncus ultricies arcu id feugiat. Null... 9 1 133 Donec sit amet nunc urna. Vivamus id dui velit, ac... 10 0 133 Maecenas aliquet pellentesque egestas. Vestibulum ... 11 0 109 armut dalda kız balkonda sallanır vay vay... 12 1 109 Duis consequat luctus rhoncus. Etiam ante lectus, ... 14 3 116 Lorem ipsum dolor sit amet, consectetur adipiscing... 15 0 2 This is the first item in the first field. 16 0 2 And this is the second item in second field.

你能帮我吗,我该如何处理?最好的问候.

Could you help me, how do I manage this? Best regards.

推荐答案

你需要一个聚合函数来把 iceriks 连接在一起,如果你还想显示最小 id,你还需要一个聚合函数来获得它.

You need an aggregate function to concatenate together the iceriks, and if you also want to show the minimum id, you also need an aggregate function to get that.

这应该可以:

SELECT MIN(id), fikraNo, maddeNo, GROUP_CONCAT(icerik ORDER BY id DESC SEPARATOR ' ') FROM `table` GROUP BY fikraNo, maddeNo

演示在这里:sqlfiddle/#!2/ad7c93/1

更多推荐

连接两列中具有相同值的两行

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

发布评论

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

>www.elefans.com

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