Using python with sqlite3
Question: I am using python 3.4.2 with sqlite3. import pypyodbc as pyodbc import sqlite3

    
    
    print ("Connecting via ODBC")
    #conn = pyodbc.connect('DSN=NZSQL')
    print ("Connecting via ODBC")
    # get a connection, if a connect cannot be made an exception will be raised here
    conn = pyodbc.connect("DRIVER=NetezzaSQL;SERVER=xyz;port=123;DATABASE=qwe;UID=hjk;PWD=lkm;")
    cur=conn.cursor()
    print("connected")
    
    
    def fetch():
        sql_string="CREATE TABLE A as select distinct a.cust,a.loc, a.key,a.bus, \
        a.prod,a.sty_code,a.color_code,trim(sty_code) AS style_code ,trim(color_code) AS colour_code, \
        price,collect, silh, sty_grp,net_sales_amt_usd,net_sales_qty, AUR,mfsrp \
        from final a where a.date between '29Jun2014' and '30May2015' \
    
        cur.execute('%s'%(sql_string))
        cur.execute("select * A;")
        sales=list(cur)
        for row in sales: 
    
        print(row)
    

output: (Decimal('1567678888'), 'QWERTY', None, datetime.date(2015, 1, 20),
Decimal('1567675888'), '52122', 'LID8T', '52122', 'LID8T', '52122_LID8T',
'Legacy CAP', 'Handle', ' CAP Pouch', Decimal('282.00000'), Decimal('2'),
Decimal('141.00000000000000000000000'), '1. $0 - $200')

Question: 1\. As this value is directly imported from ntezza database so can
we format the values in proper format? How? 2\. How to display
Decimal('1567678888') as 1567678888 as number? 3\. How to display
datetime.date(2015, 1, 20) as proper date time format?


Answer: Firstly be more specific with your question.Now for your question,

To get top N records in sqlite3 ,

    
    
    SELECT * FROM SO_table LIMIT 5;
    

For order By:

    
    
    SELECT * FROM SO_table ORDER BY upvotes ASC;
    

