0

我需要一些帮助才能正确列出邮件。现在邮件列表按日期/时间正确,但显示的字母文本错误。

SELECT 
  id, 
  userid, 
  sendid, 
  left(mess,35), 
  max(xdatum) AS maxtid, 
  status, 
  bild, 
  sendname, 
  sendinfo 
FROM mailbox 
WHERE userid='" &Session("userid")& "' 
GROUP BY sendid 
ORDER BY maxtid desc

解决方案:

最后一条短信来自 Lisa33,09:33

最后一条短信来自 AAAdam,08:22

等等..

如果我能在每个组中获得 totmail 的奖励..like:

来自 Lisa33 的最后一条短信 msg..(4),09:33

来自 AAAdam 的最后一条短信 ..(1),08:22

4

1 回答 1

0

试试这个,使用子选择来获取最大 xdatum,然后将它与主表连接起来以获取其他列

SELECT 
  id, 
  userid, 
  sendid, 
  left(mess,35), 
  Sub1.maxtid, 
  status, 
  bild, 
  sendname, 
  sendinfo 
FROM mailbox 
INNER JOIN
(
    SELECT sendid, max(xdatum) AS maxtid
    FROM mailbox 
    WHERE userid='" &Session("userid")& "' 
    GROUP BY sendid 
) Sub1
ON mailbox.sendid = Sub1.sendid
AND mailbox.xdatum = Sub1.maxtid
WHERE userid='" &Session("userid")& "' 
ORDER BY maxtid desc
于 2013-10-23T09:14:34.720 回答