草庐IT

MySQL concat 与 INNER JOIN

coder 2023-10-10 原文

我有 2 个表:ma​​nuscriptma​​nuscript_log

我想为每个手稿显示在同一行的相应日志

例子: 我有两份手稿 1 和 2。 稿件1有2条日志,稿件2有3条日志。

我想在查询中得到两个结果,按手稿 ID 分组:

manuscript_id     manuscript_log
1.                      1,2
2.                     3,4,5

SELECT manuscript.id, manuscript_log.log_number
FROM manuscript INNER JOIN manuscript_log
              ON manuscript.id = manuscript_log.manuscript_id

最佳答案

您可以使用 GROUP_CONCAT聚合函数

SELECT manuscript.id, GROUP_CONCAT(manuscript_log.log_number)
FROM manuscript INNER JOIN manuscript_log
              ON manuscript.id = manuscript_log.manuscript_id
GROUP BY manuscript.id

关于MySQL concat 与 INNER JOIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16774394/

有关MySQL concat 与 INNER JOIN的更多相关文章

  1. php - yii2:如何使用 innerjoin 在索引( GridView )中添加一列 - 2

    我想在GridView::widget中添加一列$dataProvider,'filterModel'=>$searchModel,'columns'=>[['class'=>'yii\grid\SerialColumn'],'id','owner_id','situation','address',[//'attribute'=>'address','format'=>'html','label'=>'Image','value'=>function($data){returnHtml::img('http://iicity.ir/'.$data['address'],['width

  2. php - Doctrine2 Symfony2 innerJoin QueryException 预期 Doctrine\ORM\Query\Lexer::T_WITH,得到 'ON' - 2

    作为我网站的一部分,我正在尝试使用Symfony2和Doctrine2创建标记(folksonomy)系统。我正在按照下面文档中的表格和查询示例来创建我的Doctrine实体:http://dablog.ulcc.ac.uk/wp-content/uploads/2007/12/tagging_folksonomy.pdf当我尝试将MySQL查询(在文档中给出)转换为DoctrineQueryBuilder查询时,我在innerJoins中遇到错误。示例如下:来自文档的MySQL查询:SELECTtag_text,COUNT(*)asnum_tagsFROMTag2Postt2pINN

随机推荐