Mysql optimize Query

Asked

Viewed 43 times

0

SELECT data_envio,
       nota_fiscal,
       nome_cliente,
       modelo.nome,
       conteudo.quantidade
  FROM conteudo,
       equipamento,
       caixa,
       pedido,
       cliente,
       modelo
 WHERE pedido.numero_pedido = conteudo.numero_pedido
   AND cliente.idcliente = pedido.cliente_idcliente
   AND modelo.idmodelo = conteudo.modelo_idmodelo
 LIMIT 20,40

Amostra da resposta do SQL

Clarifying that certain tables have tens of thousands of records.

  1. First, I want to inform myself, about some modifier capable of the intention of delimiting a section of the database to be processed, defining the initial line and final line. To your knowledge, the LIMIT modifier runs at the end of the processing and does not meet this goal.

  2. Another need, is to group the repetition of the products (column name) and add the quantity. Note in the table that we have for a common invoice, repeat product lines.

  3. You need to present up to the limit of 200 records or less, provided you show the last rows a complete set of the same tax note (that is, you cannot submit partial data for a tax note number).

inserir a descrição da imagem aqui

  • The SQL language does not have mechanisms that delimite a section of the database to be processed, what you can use is a clause where stipulates values of fields to be considered (which does not necessarily correspond to "excerpt from the database" in its usual understanding). Item 2 is achieved with the use of the GROUP BY clause and the SUM aggregation function, see the DBMS documentation From what I understood of your item 3 you would have to implement in your application..

  • 1

    I believe that explanations of the structure of your database and the purpose of your query. Without knowing what data set you need and having an executable example, it is virtually impossible to help you

  • Note that your tables equipamento and caixa They are listed in the FROM clause but do not have conditions of joining in the WHERE clause, which implies a Cartesian product, which I do not think is what you want. Study how to make joints.

  • I believe you can solve your problem by creating Views.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.