N0 Te Importa

Generation

generate functionSun, 09 Jul 2023

script mysql nombre server:127.0.0.1 db: "aaaa" user:"root" pass:"" tabla: "anuncios" iterar en el campo "cuidad_slug" y hacer cumplir la regla que hayan 10 anuncios por cada valor único de "ciudad_slug" por cada una de las "categoria_id" que son la 1 la 2 y la 3. Tiene que haber 10 de cada categoria_id por cada ciudad_slug. Los que hay se respetan y si no cumplen con la condicion se rellenan de forma aleatoria hasta llegar a 10

def script_mysql(server, db, user, passwd, table): import mysql.connector import random import collections cnx = mysql.connector.connect(user=user, password=passwd, host=server, database=db) cursor = cnx.cursor() # seleccionar 10 anuncios del 1 al 10 de cada ciudad_slug por cada categoria_id query = (("SELECT * FROM {} WHERE categoria_id = 1 GROUP BY ciudad_slug LIMIT 10".format(table)), ("SELECT * FROM {} WHERE categoria_id = 2 GROUP BY ciudad_slug LIMIT 10".format(table)), ("SELECT * FROM {} WHERE categoria_id = 3 GROUP BY ciudad_slug LIMIT 10".format(table)), ) # seleccionar todos los anuncios query_all = ("SELECT * FROM {}".format(table),) # array de

Want to kickstart your project?Use the new AI Studio to create your code