3

我如何从表格中获取最新日期。如果我告诉你我的意思,也许会更好。

这是我当前的表格输出

TransactionID          Title           Date
23132                  Locaton         2013-05-17 10:02:04
23131                  Novuel          2013-05-16 16:26:45
23130                  Novuel          2013-05-16 11:41:21
23129                  Locaton         2013-05-15 15:02:47
23128                  Mama Rosa       2013-05-15 14:42:44
23127                  Locaton         2013-05-14 18:21:32
23126                  Rohan           2013-05-14 12:46:56

这是所需的输出:

TransactionID          Title           Date
23132                  Locaton         2013-05-17 10:02:04
23131                  Novuel          2013-05-16 16:26:45
23128                  Mama Rosa       2013-05-15 14:42:44
23126                  Rohan           2013-05-14 12:46:56

如您所见,我只想要mysql中每个标题的最新日期。

这就是我迄今为止尝试获得所需输出的方式:

    ("SELECT t.transactionid,
       ct.title,
       max(t.transactiontime)
FROM exp_channel_titles AS ct
LEFT JOIN transactions AS t ON (ct.entry_id = t.restaurant_id)
WHERE t.transactiontime IN
    (SELECT max(t.transactiontime)
     FROM transactions AS t)
GROUP BY ct.entry_id
ORDER BY t.transactiontime DESC");
4

4 回答 4

1
select * from t t1
where 
NOT EXISTS (select transactionID 
                from t where t.Title=t1.title
                         and t.date>t1.date)

SQLFiddle 演示

于 2013-04-17T08:57:55.953 回答
0
SELECT MAX(t.transactionid) AS TRANSACTION_ID, ct.title, MAX(t.transactiontime)
FROM exp_channel_titles as ct
LEFT JOIN transactions as t 
on (ct.entry_id = t.restaurant_id)
GROUP BY CT.TITLE
于 2013-04-17T08:59:48.217 回答
0

试试这个:w3schools

不知道是不是你的意思

于 2013-04-17T09:23:32.530 回答
0

你可以试试这个:

SELECT t1.transactionid, ct.title, t1.transactiontime
FROM exp_channel_titles as ct
LEFT JOIN
(Select t.* from transactions as t 
INNER join (SELECT max(TransactionID) FROM transactions group by Title having     transactiontime=max(transactiontime) ) temp
ON temp.TransactionID= t.TransactionID) as t1
on ct.entry_id = t1.restaurant_id
于 2013-04-17T08:55:13.497 回答