Problem with SQL return

Asked

Viewed 43 times

0

I have the following 3 tables: Clients, Requests, Requests:

Customers:

inserir a descrição da imagem aqui

Solicitations:

inserir a descrição da imagem aqui

requeca_description

inserir a descrição da imagem aqui

The request table links to the client table(cliente_id = id[client table]) and linked to the requested table])

I need to return a client who has made more than one request!

For example I need all clients who have consulted and examined together. How do I mount a query in this scenario for this?

1 answer

0

select cli.nome, group_concat(solicitacoes_descricao_id) solicitacao_descricao
  from clientes cli, solicitacao_descricao sd, solitacoes sol
 where cli.id = sol.cliente_id
   and sol.solicitacoes_descricao_id = sd.id
 group by cli.nome
 having count(sol.solicitacoes_descricao_id) > 1
  • I want the opposite, I want "ALL" people who participated in more than one request. then the filter has to be for more than one request, for example I want every customer who participated in the request with id 1,2,3(the 3 together).

  • I made a modification, it would be that?

  • I saw it, it wouldn’t be.. Because it has a customer filter.. the only filter would be in the request_description... I just want the filter on it the customer is what I want it to return. For example I want all customers who participated in the request 1,2,3,4 ... ai the sql returns me a list of clients

  • what fields you want to return? sol set.id id_request, sd.Description, cli.id

  • may be just the client.name, the modification will not work pq o in works as several OR and I want the opposite.. I want it to be mandatory that the customer has attended 2 or more requests to appear... It had to be several "AND" that works. But I’ve tried so many ways.

  • I used group_concat, which will bring all requests from each client with the condition of having 2 or more requests

  • Almost that, I just need to be requests that choose instead of being >=2 as I do?

  • as I don’t have the bank here, it gets more complicated to test rs. but see if the change would be that?

  • But then I come back to the problem of having to be mandatory the requests to appear would have as we talk?

  • is pq Voce put in the above comment that needed only requests that you choose instead of >=2

  • Then the client one, participates in the request_description(3,8,13) the 3 joints want to put a filter like this, All customers who participated in the 3,8,13 requests together.

Show 6 more comments

Browser other questions tagged

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