none
(Sumber: milis DOTNET) perintah select RRS feed

  • Pertanyaan

  • salam semuanya,

    mau nanya nih saya ada tabel dimana datanya seperti ini

    nota         nilai           ket

    BL1        100000     BL

    BL2        50000       BL

    JL1         120000     JL

    JL2         70000        JL

    BL3        200000      BL

    JL3         570000      JL

    bagaimana syntax select untuk bisa summary nilai masing2 ket dan sisa ya

    jadi format yang saya mau itu seperti ini

    Nilai_beli       Nilai_jual     Selisih (nilai jual - nilai beli)

    350000         720000       370000  


    Best Regards,
    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Jumat, 28 Desember 2012 07.08
    Moderator

Jawaban

  • mudah2an ini bisa membantu..

    select A.Nilai_Beli as Nilai_Beli, B.Nilai_Jual as Nilai_Jual, B.Nilai_Jual - A.Nilai_Beli as Selisih from

    (select SUM(C.nilai) as Nilai_Beli, C.tmpfield from

    (select *,'1' as tmpfield from tblnota) C

    group by ket, tmpfield

    having ket='BL') A

    inner join

    (select SUM(C.nilai) as Nilai_Jual, C.tmpfield from

    (select *,'1' as tmpfield from tblnota) C

    group by ket,tmpfield

    having ket='JL') B on A.tmpfield=b.tmpfield

    Dijawab oleh: Arief Setiawan


    Best Regards,
    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Jumat, 28 Desember 2012 07.08
    Moderator