如何创建虚拟表或如何在同一行中按日期排序


How to create a virtual table or how to order by date in same row

嗨,我的数据库里有这个。

id | status1 | status2 | time1 | time2 | time3  | time4  | time5   | userid | itemuid
 1 |    2    |    1    | 000001| 000003| 000008 |   0    | 000099  |   15   |   620
 2 |    2    |    1    | 000002| 000004| 000001 |   0    | 000002  |   620  |   15

现在我需要回显一些通知,问题是时间在同一行。。所以这是一个很大的问题,例如,我的条件看起来像

if ($actualuser == $userid && $status1==2)
echo  notification 
echo time4
if ($actualuser == $userid && $status2==1)
echo  notification 
echo time2

这意味着每个循环都有一个,唯一的问题是我需要从最新的(最新的)到最旧的,就像下面的例子。。。在这个例子中,这个想法将设置或排序所有的时间,因为它只是一个时间列。。这是posible吗?

item id1 time(000099) 
item id1 time(000008)
etc
item id1 time(000001)
item id1 time(0)
item id2 time(0)

我该怎么做?顺便说一句,这两个条件只是举个例子。。我有4或6个条件使用相同的格式,但也许我不能这样做。。我能做些什么来设置通知。。。

谢谢。。Im丢失

所以,正如我在评论中所说,你需要做如下操作:

select t.*, t2.times from yourtable t, (
    select id, time1 times from yourtable union
    select id, time2 from yourtable union
    select id, time3 from yourtable union
    select id, time4 from yourtable union
    select id, time5 from yourtable ) t2
 where t.id = t2.id
 order by t2.times desc