Nu vet jag inte vad du använder för dbms, men...
order by case when a.modified > a.created then a.modified else a.created end desc
eller någon liknande variant hade jag försökt mig på.
mvh
2 svar · 406 visningar · startad av Mog
Jag har en sql-fråga som ser ut så här;
$query = 'SELECT a.*, ' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'.
' FROM #__content AS a' .
($show_front == '0' ? ' LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id' : '') .
' INNER JOIN #__categories AS cc ON cc.id = a.catid' .
' INNER JOIN #__sections AS s ON s.id = a.sectionid' .
' WHERE '. $where .' AND s.id > 0' .
($access ? ' AND a.access <= ' .(int) $aid. ' AND cc.access <= ' .(int) $aid. ' AND s.access <= ' .(int) $aid : '').
($catid ? $catCondition : '').
($secid ? $secCondition : '').
($show_front == '0' ? ' AND f.content_id IS NULL ' : '').
' AND s.published = 1' .
' AND cc.published = 1' .
' ORDER BY '. $ordering;
$ordering innehåller "a.modified DESC, a.created DESC" eller "a.created DESC, a.modified DESC"
Nu vill jag ha ett tredje alternativ där sorteringen blir på båda kolumnerna, som det är nu kommer alla a.created före a.modified vid "a.created DESC, a.modified DESC" även om det finns nyare i a.modified.
Tyckte det borde gå med nån "select as" och sortera på denna men jag får inte ihop det.
Nu vet jag inte vad du använder för dbms, men...
order by case when a.modified > a.created then a.modified else a.created end desc
eller någon liknande variant hade jag försökt mig på.
mvh
Tackar !
Funkar klockrent.