[Python-es] OFFTopic: error SQL

Gonzalo Alejandro Vergara Almonacid go.vergara.a en gmail.com
Mie Ene 23 22:19:22 CET 2013


si la fecha se guarda como tipo date, deberías hacer algo como esto

"SELECT COUNT(*) FROM tienda_registro WHERE id_producto =
65656  AND fecha_servidor = DATE('2013-01-22’)”

Gonzalo Vergara Almonacid
Web Developer and Front End designer
Ingeniería Civil Informática
Universidad del Bío-Bío

 *De:* Diego Uribe Gamez <diego.uribe.gamez en gmail.com>
*Enviado el:* 23 de enero de 2013 16:23
*Para:* La lista de python en castellano <python-es en python.org>
*Asunto:* [Python-es] OFFTopic: error SQL

Estoy haciendo un query que me dice cuantas veces hoy fue ingresado un
producto por id, pero me sale un error cuando intento realizar
la búsqueda sobre dos columnas, en cambio si lo hago sobre una queda bien.

Este sale bien:
--------------------------------------------------------------------
query = "SELECT COUNT(*) FROM tienda_registro WHERE fecha_servidor =
'2013-01-22'"
--------------------------------------------------------------------

Este que consulta el conteo usando dos columnas sale mal
--------------------------------------------------------------------
query = "SELECT COUNT(*) FROM tienda_registro WHERE id_producto = 65656 ,
fecha_servidor = '2013-01-22'"

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in
execute
    self.errorhandler(self, exc, value)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36,
in defaulterrorhandler
    raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near ' fecha_servidor = '2013-01-22'' at line 1")
--------------------------------------------------------------------

Alguien me podría decir que esta mal?

Gracias.

-- 
 *Diego Alonso Uribe Gamez*
------------------------------



*Desarrollador web*

Twitter: @DiegoUG <http://www.twitter.com/DiegoUG>

Google+: http://gplus.to/diegoug
------------------------------





_______________________________________________
Python-es mailing list
Python-es en python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20130123/48ef220b/attachment.html>


Más información sobre la lista de distribución Python-es