How to work out on these query?

  • my table looks like

    invoice_no model_ref item_type item_no invoice_qty

    tn/0002/13-14 - I 5000350 5

    " - K 6000350 10

    " 6000350 X 5000242 15

    " 6000350 X 5000470 2

    MB/0006/13-14 - K 6000370 10

    " 6000370 X 5000460 10

    " 6000370 X 5000480 1

    like i ve lakh of recors in my table

    table struct:

    +++++++++

    create table invoice_item

    (

    invoice_no varchar(20),

    model_ref int,

    item_type char(10),

    item_no varchar(20),

    invoice_qty int

    )

    insert into invoice_item(invoice_no,model_ref,item_type,item_no,invoice_qty)

    values ('tn/0002/13-14','-','I','5000350','5')

    ' ('tn/0002/13-14','-','K','6000350','10')

    ' ('tn/0002/13-14','6000350','X','5000242','15')

    My EXPECTING O/P:

    invoice_no item_no Sales Free

    tn/0002/13-14 5000350 5 0

    tn/0002/13-14 5000242 10 5

    tn/0002/13-14 5000470 0 2

    MB/0006/13-14 5000460 10 0

    MB/0006/13-14 5000480 0 1

    here Item_types "I" directly billed item so it ll reflect free "0" always.

    but when we billed along with "K"(kit) highest value takes billed remaining as free(I.E 6000350 kit was billed on tn/0002/13-14 with 10 QTY

    actually it contains 5000242 = 15 QTY & 5000470 = 2 QTY

    highest values (5000242=15) is less from kit billed. shows like line number 2,3 from my expecting O/P table)

    how to do that?

  • If you could let us see how far you've already got, we might be able to help out seeing where the problem is.

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply