doujiao7483 2013-11-17 00:13 采纳率: 0%
浏览 44
已采纳

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

Hi i have this in my database.

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

Now i need to echo some notifications the problem is time is in the same row.. so its a big huge problem to get this in order for example my conditions would look like

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

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

This goes insinde a for each loop and the only problem is i need to echo from latest(newest) to oldest, like the example below... In this examples the idea would set or Order all the times as it was just one time columns.. is this posibble?

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

how can i do this? Bye the way this 2 conditions are just for example.. i have like 4 or 6 conditions using the same format, but maybe i cant do this this way.. what can i do to set notifications for this...

thanks.. Im lost

  • 写回答

1条回答 默认 最新

  • doutuan6158 2013-11-17 00:30
    关注

    So, As I said in comments you need to do as folow:

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题