0

このsqlコマンドはsqlitemanagerで正常に機能しますが、私のAndroidアプリケーションではこれは説明をソートしません...

select t._id,  u.name, c.commdate, c.message
from tickets t, users u, comments c
where c.userid = u._id and c.ticketid = t._id
and t.status = 5
group by t._id
having max(c.commdate)
order by c.commdate desc
4

1 に答える 1

0

「持っている」部分が問題だと感じています。試してみてください(テストされていません);

SELECT t._id, u.name, c.commdate, c.message
FROM tickets t
JOIN comments c ON (t._id = c.ticketid)
-- Find most decent comments on tickets, but handle lack of any comments
LEFT JOIN (
    SELECT c2.ticketid, MAX(c2.commdate) as max_commdate
    FROM comments c2
) AS latest ON (c.ticketid = latest.ticketid AND c.commdate = latest.max_commdate)
JOIN users u ON (c.userid = i._id)
WHERE t.status = 5
ORDER BY t._id DESC, c.commdate DESC
于 2012-04-09T12:01:28.227 に答える