Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/06/2010, 12:22
Avatar de Nekeniehl
Nekeniehl
 
Fecha de Ingreso: julio-2009
Ubicación: Berlin, Alemania / Granada, España
Mensajes: 132
Antigüedad: 14 años, 9 meses
Puntos: 6
Respuesta: Obtener resultados de una query Python

Mira yo hago con mysql, no sé si te servirá es solo un ejemplo:

Código Python:
Ver original
  1. def Conn (host = "localhost", database = "wasadu", username = "root", password = "1234"):
  2.     """Connection to mysql
  3.    return cursor from the database"""
  4.     db = MySQLdb.connect (host,username,password,database)
  5.     cursor = db.cursor (cursorclass = MySQLdb.cursors.DictCursor)
  6.     return cursor
  7. def ChannelTotal ():
  8.     """Return the total of the price group by channel"""
  9.     date = CalculateFinishAndStartDates ()
  10.     finish = str (date[0])
  11.     start = str (date[1])
  12.     sql = """SELECT channel, SUM(price_sold) as total FROM users_tracking ut, auctions_bids ab
  13.             WHERE ut.bid_id = ab.auction_id AND ab.flag_buynow = 1 AND event_id = 8 AND ut.date BETWEEN '""" +start+"' AND '"+finish+"""'
  14.             GROUP by channel"""
  15.     cursor = Conn ()
  16.     cursor.execute (sql)
  17.     query = cursor.fetchall ()
  18.     list = []
  19.     for num in query:
  20.         channel = str (num['channel'])
  21.         total = str (num['total'])
  22.         list.append ([channel, total])
__________________
Antes de cambiar el mundo...dá tres vueltas por tu casa

Usa Google es tu amigo ;)