0

我有以下数据:

命令

order_id    order_name        order_date         order_status 

1            iphone        20130102 13:20:00        cancelled
1            blackberry    20130102 13:00:00        cancelled
1            ipad          20130102 13:00:00        cancelled

person_id     person_name       order_id

1             harshini          1

我想在 20130102 13:00:00 到 2013 13:20:00 之间根据 order_date 查询时检索以下数据。这意味着最后取消订单。

person_name     order_name   order_date     

harshini        blackberry   20130102 13:00:00
4

2 回答 2

0

试试这个...
select p.person_name ,o.order_name,o.order_status from order_1 o,person p where orderdate=(select max(orderdate) from order_1)

于 2013-03-04T13:12:26.987 回答
0
select person_name, order_name, order_date 
from(
  select 
   o.order_id, o.order_name, o.order_date, o.order_status,
   p.person_id, p.person_name, p.order_id,
   row_number() over (/*partition by person_id*/ order by order_date desc) as rnk
  from order o join person p on (o.order_id = p.order_id)
  where o.order_status = 'canceled'
   and o.order_date between 
       to_date('20130102 13:00:00','yyyymmdd hh24:mi:ss') and
       to_date('20130102 13:00:00','yyyymmdd hh24:mi:ss')
)
where rnk = 1;

但是看评论,你的设计有一些问题。

于 2013-03-04T13:40:36.957 回答