Buen día.
Estoy realizando una consulta mysql, insert select, el problema es que de 180,000 datos que se tienen que insertar por sucursal, máximo me inserta 9,000.
Podrían ayudarme?
Código PHP:
$query1="SELECT
unidades.id,
unidades.codigo,
unidades.nombre,
unidades.tipo
FROM
unidades
WHERE
unidades.codigo != 'MANAGER'
AND
unidades.codigo != ''
ORDER BY
unidades.id ASC";
$sql1=mysql_query($query1);
while($row1=mysql_fetch_row($sql1))
{
if($row1[3]=="PLANTA")
{
$store=$row1[2];
}else
{
$selectsucursal="SELECT
relaciones_uniones.id_relacion,
relaciones.id_planta,
unidades.nombre as nombre
FROM
relaciones_uniones
Inner Join relaciones on relaciones.id=relaciones_uniones.id_relacion
Inner Join unidades on relaciones.id_planta=unidades.id
WHERE
relaciones_uniones.id_sucursal='".$row1[0]."'
ORDER BY
relaciones.fecha DESC";
$sqlsucursal=mysql_query($selectsucursal);
while($rowntea=mysql_fetch_row($sqlsucursal))
{
$store=$rowntea[2];
break;
}
}
$query2="INSERT INTO
kpi
(ciudad, planta, sucursal, canal, orden, ticket, tipo_orden, fecha_elaboracion, fecha_promesa, fecha_finalizacion, fecha_entrega, lote, tiempo_de_ciclo, usuario, cliente, direccion, colonia, municipio, cp, telefono, creditos, alta, total_prendas, tipo, descripcion, cantidad, color, precio_unitario, importe, subtotal, credito_usado, descuento, efectivo, estatus_transaccion, cambio, total, estatus)
SELECT
'Guadalajara',
'".$store."',
'".$row1[2]."',
'".$row1[3]."',
".strtolower($row1[1])."_prendas_tickets.id_orden as orden,
".strtolower($row1[1])."_prendas_tickets.id_ticket as ticket,
'Venta',
".strtolower($row1[1])."_tickets.fecha_aper as fecha_elaboracion,
".strtolower($row1[1])."_tickets.fecha_promesa as fecha_promesa,
".strtolower($row1[1])."_tickets.fecha_asignacion as fecha_finalizacion,
".strtolower($row1[1])."_tickets.fecha_entrega as fecha_entrega,
".strtolower($row1[1])."_tickets.id_lote as lote,
((lotes.hora_final)-(lotes.hora_inicio)) as tiempo_de_ciclo,
".strtolower($row1[1])."_ordenes.atendio as usuario,
".strtolower($row1[1])."_ordenes.nombre as cliente,
clientes.direccion as direccion,
clientes.colonia as colonia,
clientes.ciudad as municipio,
clientes.cp as cp,
".strtolower($row1[1])."_ordenes.telefono as telefono,
clientes.credito as creditos,
clientes.fecha as alta,
clientes.prendas as total_prendas,
'Prenda',
".strtolower($row1[1])."_prendas_tickets.prenda as descripcion,
".strtolower($row1[1])."_prendas_tickets.cant as cantidad,
".strtolower($row1[1])."_prendas_tickets.color as color,
".strtolower($row1[1])."_prendas_tickets.precio_unitario as precio_unitario,
".strtolower($row1[1])."_prendas_tickets.importe as importe,
".strtolower($row1[1])."_ordenes.subtotal as subtotal,
".strtolower($row1[1])."_ordenes.credito as credito_usado,
".strtolower($row1[1])."_ordenes.frecuente as descuento,
".strtolower($row1[1])."_ordenes.pago as efectivo,
".strtolower($row1[1])."_ordenes.corte as estatus_transaccion,
".strtolower($row1[1])."_ordenes.cambio as cambio,
".strtolower($row1[1])."_ordenes.total as total,
".strtolower($row1[1])."_tickets.estatus as estatus
FROM
".strtolower($row1[1])."_prendas_tickets
Inner Join ".strtolower($row1[1])."_tickets on ".strtolower($row1[1])."_tickets.id=".strtolower($row1[1])."_prendas_tickets.id_ticket
Inner Join ".strtolower($row1[1])."_ordenes on ".strtolower($row1[1])."_ordenes.id=".strtolower($row1[1])."_prendas_tickets.id_orden
Inner Join clientes on clientes.telefono=".strtolower($row1[1])."_ordenes.telefono
Inner Join lotes on lotes.id=".strtolower($row1[1])."_tickets.id_lote
WHERE
".strtolower($row1[1])."_tickets.fecha_aper>'2012-01-01'
AND
".strtolower($row1[1])."_tickets.fecha_aper<'2013-11-12'
ORDER BY
".strtolower($row1[1])."_tickets.fecha_aper ASC
";
mysql_query($query2);
echo $row1[2]." ".mysql_affected_rows()."<br/>";
}
echo mysql_error();