douling8087 2014-01-08 00:25
浏览 6
已采纳

PHP / MySQL - 在一列中返回值[关闭]

I need to select same values in 1 column, for example: Select * from Table, this needs to return like this:

ColumnName | ColumnValue
google         1,2,3,4
facebook       1,2,3,5

The actual query, returns this.

ColumnName | ColumnValue
google           1
google           2
google           3
google           4
facebook         1
facebook         2
facebook         3
facebook         4

Can someone help me?

Thanks!

  • 写回答

3条回答 默认 最新

  • douzhoubing2805 2014-01-08 00:29
    关注

    You're looking for GROUP_CONCAT:

    SELECT GROUP_CONCAT(ColumnValue SEPARATOR ', ') FROM table GROUP BY ColumnName;
    

    Considering the reasoning behind relational databases though, you should be cautious about purposely denormalizing your results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算