Consultation based on two parameters VISUAL FOXPRO

0

Good morning! I would like to know how I can make a query to obtain the results of my records depending on the date.

I have PEDPOS which is the order and I have CMOV which is the move that was made (101 delivered 102 returned) I have the date on which it was made every CMOV

What I want to do is for example if an article that has:

PEDPOS    CMOV    FECHA
123       102     20-02-17
123       101     22-03-17

Here as you can see this request is already discarded because it was delivered, as, what I want to know is how I can do to get those that are not yet delivered as for example this:

PEDPOS    CMOV    FECHA
124       102     15-03-17
124       101     23-03-17
124       102     04-04-17

Here the product is not returned yet, as it had previously been delivered but returned again

    
asked by Ale Loera 10.07.2017 в 18:15
source

1 answer

0

Ale, you can try these consecutive selections. The last cursor (cur4) gets the list you need.

** obtener cursor el ultimo movimiento de cada pedido
select  pedpos as c1pedpos, max(fecha) as ultfch, count(*) as cantreg from pedido group by 1 into cursor cur1
brow

** obtener los pedido a excluir porque tuviero moviento 101 y 102 en la misma fecha
select * from pedido p1 inner join cur1 c1 ;
           on p1.pedpos = c1.c1pedpos and p1.fecha = c1.ultfch ;
        where cantreg > 2  and cmov = 101 into cursor curexcluir
brow 

**  obtener los posible pedidos que cumplen la condicion >2 movimientos                                                   
select * from pedido p1 inner join cur1 c1 ;
           on p1.pedpos = c1.c1pedpos and p1.fecha = c1.ultfch ;
        where cantreg > 2   into cursor cur3 
brow

** detalle de los que cumplen la condicion
select * from pedido ; 
        where pedpos in (select pedpos from cur3 where cantreg > 2 ) ;
          and pedpos not in ( select pedpos from curexcluir)   ;
        into cursor cur4
brow
    
answered by 11.07.2017 в 19:45