我正在尝试选择行中的最新日期(不在列中)
它必须是 'articles_date_added' 或 'articles_last_modified' 在这样的表中
Id | ... | ... | articles_date_added | articles_last_modified | ...
我的真实查询如下所示:
select
a.articles_id, a.authors_id, a.articles_date_added,
a.articles_last_modified,
IF(a.articles_last_modified >= a.articles_date_added,
a.articles_last_modified,
a.articles_date_added) as latestdate,
ad.articles_viewed,
ad.articles_name, ad.articles_head_desc_tag,
COUNT(vh.articles_id) as total_votes,
SUM(v.vote_value)/COUNT(v.vote_value) AS vote_avg,
au.authors_name, td.topics_name, a2t.topics_id
from
" . TABLE_ARTICLES . " a
left join " . TABLE_AUTHORS . " au using(authors_id)
left join VOTE_HISTORY vh using (articles_id)
left join VOTE v using (vote_id),
" . TABLE_ARTICLES_DESCRIPTION . " ad,
" . TABLE_ARTICLES_TO_TOPICS . " a2t
left join " . TABLE_TOPICS_DESCRIPTION . " td using(topics_id)
where
(a.articles_date_available IS NULL or
to_days(a.articles_date_available) <= to_days(now())) and
a.articles_status = '1' and a.articles_id = a2t.articles_id and
ad.articles_id = a2t.articles_id and
ad.language_id = '" . (int)$languages_id . "'
and td.language_id = '" . (int)$languages_id . "'
and a2t.topics_id = '" . (int)$current_topic_id . "' and
au.authors_id = '" . (int)$_GET['filter_id'] . "'
GROUP BY a.articles_id
ORDER BY latestdate desc
如您所见,选择它我使用
IF(a.articles_last_modified >= a.articles_date_added,
a.articles_last_modified, a.articles_date_added) as latestdate
但它返回 1054 - 'order 子句中的未知列'latestdate'
为什么?
我在 MySql 5.0 上。