本文共 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/