博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql中GROUP_CONCAT的应用
阅读量:4045 次
发布时间:2019-05-24

本文共 430 字,大约阅读时间需要 1 分钟。

今天做项目统计,DB是mysql,结果发现一个问题,描述如下

3张表的关联,结果一个项目可能会有多个类型,所以会导致查询的记录一个项目出现多条记录,所以需要将项目类型合并在一个字段内,并只显示一条记录,测试后可以使用的语句如下:

 

 

select  t1.name as name, t2.name as type, GROUP_CONCAT( t2.name

SEPARATOR  ", " ) AS type2, t1.`desc`, t1.begin ,t1.end ,t1.status  from zt_project t1, zt_product t2, zt_projectProduct t3

  where t3.project = t1.id and t3.product = t2.id

  and     t1.begin   between '2011-01-01' and '2011-03-31'

group by t1.name

order by begin

转载地址:http://mggdi.baihongyu.com/

你可能感兴趣的文章
CCF 分蛋糕
查看>>
解决python2.7中UnicodeEncodeError
查看>>
小谈python 输出
查看>>
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
机器学习实战之决策树(一)
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
Android/Linux 内存监视
查看>>
用find命令查找最近修改过的文件
查看>>
Android2.1消息应用(Messaging)源码学习笔记
查看>>
android raw读取超过1M文件的方法
查看>>
ubuntu下SVN服务器安装配置
查看>>
MPMoviePlayerViewController和MPMoviePlayerController的使用
查看>>
CocoaPods实践之制作篇
查看>>