我怎样才能得到我桌子的最新记录

时间:2013-04-17 08:30:30

标签: mysql

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

这是我当前的表格输出

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 个答案:

答案 0 :(得分:1)

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

SQLFiddle demo

答案 1 :(得分: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

答案 2 :(得分: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

答案 3 :(得分:0)

试试这个:w3schools

不确定这是不是你的意思

相关问题