我正在使用一个包含多个联接和组连接的复杂查询,下面是查询:
select a.packagename as packagename, a.packageid as packageid,
sum(a.packageduration) as days, (a.packageprice + a.seater_4) as price,
b.statename,
substring_index(GROUP_CONCAT( DISTINCT (select f.placename ) SEPARATOR ',
'),',',4) placename,
substring_index(GROUP_CONCAT( DISTINCT (select d.packagetypename )
SEPARATOR ', '),',',4) packagetypename
from tblpackages a
join tblstates b on b.stateid = a.stateid
join tblpackage_packagetypes c on c.packageid = a.packageid
join tblpackagetype d on d.packagetypeid = c.packagetypeid
join tblpackageplaces e on e.packageid = a.packageid
join tblplaces f on f.placeid = e.placeid
where d.placename = "placename"
group by a.packageid
我的分组\u concat for packagetypename在每个查询中显示4个值,而placename只显示where子句中给出的1个值?
由于查询是按包id分组的,对于任何包,我有n个位置。。。。查询按逻辑正常工作,但我想显示对应包id的所有包
2条答案
按热度按时间t8e9dugd1#
带位修改的OUR查询输出
pname,pid,days,price,statename,placename,packagetypename
测试1,1,3,111,xyz,(katra,shiv khori),宗教
测试2,2,3,444,xyz,(katra),宗教
test3,3,3,445,xyz,null,(家庭,夫妻,冒险,朋友)
测试4,4,555,xyz,(katra,patnitop,sanasar,nathatop),(宗教,家庭,夫妻,冒险)
test6,666,,null,(家庭,冒险,朋友)
不需要包id 3和6
fnatzsnv2#
我建议把标准移到
WHERE
条款ON
子句,并使该联接成为左联接: