Doubt with SQL search

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
  

Poston Mon, 19 May 2008 8:57 am

Good morning, I'm trying to do a quest where I should bring a table some items. However in the table there are 4 pk. Logo in the search if it exists in the table 1 1 2 item branch cia seq 0 1 1 2 item branch cia seq 1 1 1 2 item branch cia seq 2 CLA 1 1 2 item branch seq 3 he will search these 4 items, with the same name, however the different seq.
Now I need it to do the normal search, only instead of searching for all items, I need you to do the search for item 1 only (item of the same name).

Detail: I even thought the distinct but I can't use it because I use the query in a report.


the query is: SELECT conh_id_companhia, conh_nome, fili_id_filial, fili_nome, catb_id_categoria, catb_nome, arri_id_area, arri_nome, bemp_id_bem, bemp_seq_bem, bemp_descricao, sabe_periodo, SUM (sabe_vl_bem_corrigido) valorcorrigido, SUM (bemp_vl_aquisicao) valoraquisicao, SUM (bemp_vl_mercado) valormercado FROM st_companhia, st_filial, af_area_de_risco, ct_centro_de_custo_filial, af_categoria_bem, af_subcategoria_bem, af_saldo_bem, af_bem_patrimonial WHERE bemp_id_cia = 10 AND (bemp_id_filial = 2) AND (bemp_id_categoria =: category OR: category = -1) AND bemp_situacao! = ' c ' AND sabe_id_cia = bemp_id_cia AND sabe_id_bem = bemp_id_bem AND sabe_id_filial = bemp_id_filial AND sabe_seq_bem = bemp_seq_bem AND sabe_periodo = :d t1 AND ccuf_id_companhia = sabe_id_cia AND ccuf_id_filial = sabe_id_filial AND ccuf_id_custo = bemp_id_custo AND arri_id_companhia = ccuf_id_companhia AND arri_id_filial = ccuf_id_filial AND arri_id_area = ccuf_id_area AND catb_id_categoria = bemp_id_categoria AND catb_id_companhia = bemp_id_cia AND fili_id_filial = bemp_id_filial AND fili_id_companhia = bemp_id_cia AND conh_id_companhia = bemp_id_cia GROUP BY conh_id_companhia, conh_nome, fili_id_filial, fili_nome, catb_id_categoria, catb_nome, arri_id_area, arri_nome, bemp_id_bem, bemp_seq_bem, bemp_descricao, sabe_periodo ORDER BY catb_id_categoria, arri_id_area Thank you.
victorpsl
Location: SP

--
Victor Hugo

Poston Mon, 19 May 2008 9:10 am

Hello ... I already solved the problem ... the problem was in the group by, just pulled out (bemp_id_bem, bemp_seq_bem, bemp_descricao) thank you
victorpsl
Location: SP

--
Victor Hugo


  • See also
    Replies
    Views
    Last Post


      Return to SQL

      Who is online

      Users browsing this forum: Majestic-12 [Bot] and 1 guest