Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymysql ifnull
#3
This is the section of code (Note: this is only my second attempt at writing a program):-

su_stat = []
indx = 0

sql = ('SELECT IFNULL(categories.desc,"Total") as Category, YEAR(trans_dat), sum(transactions.amount) '

       'FROM transactions '
       'inner join vendor on transactions.acct_no = vendor.acct_no '
       'inner join categories on vendor.cat_1 = categories.cat_no '
       'group by cat_1 with rollup ')

cursor.execute(sql)
su_row = cursor.fetchall()
print(su_row)
for row in su_row:
    print(row)
    su_stat.append(row)


for row in su_stat:
    print(row)
    my_c1 = row[0]
    my_amt = str(row[2])

    sudat[indx][0] = my_c1
    sudat[indx][1] = my_amt

    indx = indx + 1
    print(sudat)
    print(indx)

connection.close()
The individual rows are:-

Output:
('Food', 2018, Decimal('-31163.28')) ('Car', 2018, Decimal('-29888.81')) ('Entertainment', 2018, Decimal('-10250.68')) ('Health', 2018, Decimal('-22569.32')) ('Transport', 2018, Decimal('-4065.60')) ('Comms', 2018, Decimal('-4367.56')) ('School', 2017, Decimal('-3073.55')) ('House Hold', 2016, Decimal('-29560.66')) ('Travel', 2018, Decimal('-976.04')) ('Personal', 2018, Decimal('-152201.22')) ('Payments', 2016, Decimal('251313.75')) ('Misc', 2018, Decimal('-2319.53')) ('Misc', 2018, Decimal('-39122.50'))
Reply


Messages In This Thread
pymysql ifnull - by aland - Sep-05-2018, 08:33 AM
RE: pymysql ifnull - by buran - Sep-05-2018, 08:47 AM
RE: pymysql ifnull - by aland - Sep-05-2018, 09:48 AM
RE: pymysql ifnull - by aland - Sep-06-2018, 01:01 AM
RE: pymysql ifnull - by buran - Sep-06-2018, 05:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql Syntax error in pymysql ilknurg 4 2,454 May-18-2022, 06:50 AM
Last Post: ibreeden
  pymysql can't do SELECT * Pedroski55 3 3,050 Sep-11-2021, 10:18 PM
Last Post: Pedroski55
  pymysql won't handle some diacritic characters awarren2001AD 0 1,305 Apr-16-2020, 08:58 AM
Last Post: awarren2001AD
  pyMySQL - ROW_NUMBER in SQL statement JayCee 1 2,440 Apr-12-2020, 08:40 PM
Last Post: JayCee
  pyMySQL How do I get the row id JayCee 3 2,783 Apr-12-2020, 08:38 PM
Last Post: JayCee
  PyMySQL return a single dictionary Valon1981 2 1,856 Feb-20-2020, 04:07 PM
Last Post: Valon1981
  pymysql: formating ouput of query wardancer84 18 8,552 Oct-04-2018, 01:54 PM
Last Post: wardancer84
  get last row id in pymysql tony1812 1 11,263 Sep-26-2017, 11:25 PM
Last Post: Larz60+
  pymysql question tony1812 1 2,933 Sep-26-2017, 12:41 AM
Last Post: Larz60+
  pymysql on macos seirra tony1812 5 4,631 Sep-17-2017, 03:24 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020