【问题标题】:apply group_conact in one column and also display all other column along with the group-concat column在一个列中应用 group_conact 并显示所有其他列以及 group-concat 列
【发布时间】:2014-02-10 22:54:54
【问题描述】:

我有一个查询,如下所示:

SELECT * FROM fw_question_options 
WHERE qdetailid in (36) 
group by graphorder ORDER BY graphorder desc

现在我只想use group_concat 显示一列 id 并希望按原样显示所有其他列 类似:

SELECT group_concat(id),* FROM fw_question_options 
WHERE qdetailid in (36) 
group by graphorder ORDER BY graphorder desc

但我们不能在 mysql 中像上面那样做,我不想在 select 子句中写下所有其他列名,只想使用 * 和一个我想应用的列名 @ 987654325@.

有什么建议吗?

谢谢

【问题讨论】:

  • 感谢您的回复,但我只想使用单个查询来实现。

标签: mysql sql select group-by group-concat


【解决方案1】:

请试试这个

SELECT group_concat(id),fw.* FROM fw_question_options as fw 
WHERE qdetailid in (36) 
group by graphorder ORDER BY graphorder desc

【讨论】:

  • 这会给我 2 次我不想要的 id
  • 是的,因为您不希望在 select 语句中指定列。如果您在选择中使用 * 它会给出表格的所有列
  • 这就是我想要 group_concat 行和除组 concat one 之外的所有其他行的问题
【解决方案2】:

* 之后写入其他列,然后查询将起作用。我的建议是不要在查询中使用*

试试这个:

SELECT *, GROUP_CONCAT(id) 
FROM fw_question_options 
WHERE qdetailid IN (36) 
GROUP BY graphorder 
ORDER BY graphorder DESC

【讨论】:

  • 以上查询没有给出预期的输出
猜你喜欢
  • 1970-01-01
  • 2021-09-09
  • 2021-12-15
  • 1970-01-01
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
  • 1970-01-01
相关资源
最近更新 更多