每个modx_site_content记录可能在modx_site_tmplvar_contentvalues中有多个记录。MySQL查询子查询或分组
我需要检索两个modx_site_tmplvar_contentvalues.value其中tvv.tmplvarid = 3,tvv.tmplvarid = 1,其中tvv.tmplvarid是未来的日子,我需要返回tvv.tmplvarid 3 tvv.value这是逗号分隔的标签列表。
此查询不返回我需要的值&我不知道如何得到我想要的。
SELECT sc.id, sc.pagetitle, tvv.value, tvv.tmplvarid, tvv.id, tvv.value
FROM modx_site_content sc
left join modx_site_tmplvar_contentvalues tvv on tvv.contentid = sc.id
where published = '1'
and (tvv.tmplvarid = '3' and tvv.value >= curdate())
order by sc.id;
基本上在最后,我只需要返回的标记列表(tvv.tmplvarid = 3)在其他相关记录(tvv.tmplvarid = 1)是将来的日期。
任何想法,这可以用分组来完成吗?我实际上并不需要modx_site_content表中的任何内容。
我明白你要去哪里,但它会返回'now'之前的值。 –
SQL查询有点不对(只是更新了sql小提琴),它有一个过去的日期不返回的行。 – theon
如果在tThree.value之后添加AS日期或将AND tThree.date更改为tThree.value,则可以工作。你的速度快了0.003秒[至少在我的测试中],所以欢呼,两者都有效,但你的效率更高。 –