Query SQL Help

Asked

Viewed 31 times

0

inserir a descrição da imagem aqui

select T.n_acid,T.marca

from (select n_acid, veic_seguro, marca

from marca_acid as ma, veiculo as v

where ma.veic_seguro = v.n_veic) as T

group by T.n_acid, T.marca;

This query returns the table that appears in the photo. I need the query to return the brand of car that appears in all 8 n_acid that exist , IE, I need to return "Mercedes-Benz"

Any idea?

  • use the filter "like"

  • But I don’t want the query to have "Mercedes," I want it to get there and return it

  • with like, you can make a dynamic change in the query using php for example, there is no way you can return something specific without giving a filter for it

  • from the above query, I need to count how many times each car brand appears and see if this is equal to the count of rows from the accident table ( the accident table has a column n_acid)

  • Clarify there for us. In this case we showed you to us you need to return "Mercedes-Benz", OK. But which criterion ? You quoted the following I need the query to return the brand of car that appears in all 8 n_acid that exist What did you try to say by that ? Because the Audi also has a n_acid 8. In short, explain better why your return should be this.

1 answer

0

Try:

SELECT n_acid, marca, COUNT(*)
FROM marca_acid as ma INNER JOIN veiculo as v ON (ma.veic_seguro = v.n_veic)
GROUP BY n_acid, marca;

Ideally you would qualify the table of each field, which you can’t guess by the text of your question.

Browser other questions tagged

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