subtract two tables created by connection.cursor and display output on webpage

14 views
Skip to first unread message

Sid

unread,
Nov 24, 2015, 1:58:01 PM11/24/15
to Django users
         

I have displayed two tables on web(i.e table1 and table2) using connection.cursor from SOURCE table

  ISSUE:

  Now I have to subtract table1(fields)-table2(fields) and display the output as table3.


   so final web page will have table1,table2,table3


  PROGRAM:


  IN views.py


  #table 1

  cursor1=connection.cursor()

    cursor1.execute('''select dummy as LCR_CUSTOMER_TYPE,CUR AS CURRENCY,

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_NONOP_INS))) as LCR_NONOP_INS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_OP_INS))) as LCR_OP_INS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_NONOP_UNINS))) as LCR_NONOP_UNINS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_OP_UNINS))) as LCR_OP_UNINS

from (select *,(case when LCR_CUSTOMER_TYPE='Corporate' then 'Non-Credit Financial Entities'

else LCR_CUSTOMER_TYPE

end) as dummy from   DDA_BASED_S9_20150930) a

group by CUR,dummy

''')

    list=cursor1.fetchall();

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

      #table 2

    cursor = connection.cursor()

    cursor.execute('''select AFTERMEMO,CUR AS CURRENCY,

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_NONOP_INS))) as LCR_NONOP_INS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_OP_INS))) as LCR_OP_INS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_NONOP_UNINS))) as LCR_NONOP_UNINS, 

'$'+CONVERT(VARCHAR(20), CONVERT(MONEY, sum(LCR_OP_UNINS))) as LCR_OP_UNINS

from (select *,(case when SIC_CODE = 7215 and 

LCR_CUSTOMER_TYPE = 'Non-Credit Financial Entities' then 'NonFinancialCorp' 

when LCR_CUSTOMER_TYPE = 'Corporate' then 'Non-Credit Financial Entities'

else LCR_CUSTOMER_TYPE end) as AFTERMEMO from  DDA_BASED_S9_20150930) a

group by  CUR,AFTERMEMO

''')

list1=cursor.fetchall();


TABLE3=TABLE1-TABLE2


can anyone tell me how to do this...it will be very helpful

  thanks in advance


Reply all
Reply to author
Forward
0 new messages