每個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秒[至少在我的測試中],所以歡呼,兩者都有效,但你的效率更高。 –