|
-
Dec 26th, 2020, 05:58 AM
#1
Thread Starter
New Member
Agrupamento de varios registros em uma subconsulta
Pessoal, tenho 2 tabelas... uma com a peça e outra com os carros compartível com aquela peça.
Então para cada peça... pode existir de 1 até 10 carros compartíveis
Então preciso unir as duas tabelas e para cada peça ter suas 'compartibilidades'
porem se 1 peça tiver 10 compartibilidade (10 registros)... vão parecer 10 peças repetidas....
Hoje está assim:
Descrição Compatibilidade
Amortecedor Fiat Uno 2009
Amortecedor Fiat Siena 2010
Amortecedor Fiat strada 2008
e queria que aparecesse assim:
Descrição Compatibilidade
Amortecedor Fiat Uno 2009 / Fiat Siena 2010 / Fiat strada 2008
Fiz assim:
Code:
SELECT produtos.CODIGO AS var_cod, produtos.DESCRICAO AS var_desc, produtos.FABRICANTE AS var_fab, produtos.QUANT_ESTOQUE AS var_quant,
(SELECT TOP (1) VALOR_VV FROM Produtos_Precos WHERE (COD_PRODUTO = produtos.CODIGO) ORDER BY CODIGO DESC) AS venda, Produtos_Comp.MODELO, Produtos_Comp.ANO
FROM produtos INNER JOIN Produtos_Comp ON produtos.CODIGO = Produtos_Comp.COD_PRODUTO
WHERE (produtos.ATIVO = 1)
ORDER BY var_desc
e tentei tambem
Code:
SELECT CODIGO AS var_cod, DESCRICAO AS var_desc, FABRICANTE AS var_fab, QUANT_ESTOQUE AS var_quant,
(SELECT TOP (1) VALOR_VV
FROM Produtos_Precos
WHERE (COD_PRODUTO = produtos.CODIGO)
ORDER BY CODIGO DESC) AS venda,
(SELECT COD_PRODUTO, MODELO, ANO
FROM Produtos_Comp
WHERE (COD_PRODUTO = produtos.CODIGO)) AS Compartibilidade
FROM produtos
WHERE (ATIVO = 1)
ORDER BY var_desc
-
Dec 26th, 2020, 06:12 AM
#2
Re: Agrupamento de varios registros em uma subconsulta
The main language for this forum is English.
Grouping of multiple records in a subquery
Guys, I have 2 tables ... one with the part and the other with the cars shared with that part.
So for each part ... there can be 1 to 10 compartment cars
So I need to join the two tables and for each piece to have its 'compartments'
however if 1 piece has 10 compartments (10 records) ... it will look like 10 repeated pieces ....
Today is like this:
Description Compatibility
Shock Absorber Fiat Uno 2009
2010 Fiat Siena Shock Absorber
Shock absorber Fiat strada 2008
and I wanted it to look like this:
-
Dec 26th, 2020, 06:24 AM
#3
Thread Starter
New Member
Re: Agrupamento de varios registros em uma subconsulta
Então perguntas em outro idioma não são aceito?
-
Dec 26th, 2020, 07:51 AM
#4
Re: Agrupamento de varios registros em uma subconsulta
You have to use English, like all other threads and posts on this forum.
-
Dec 26th, 2020, 10:13 AM
#5
Re: Agrupamento de varios registros em uma subconsulta
From looking at the desired result, it seems like a "Group_Concat" function (in conjunction with Group By) could do the job.
Olaf
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|