Select only first place in the first half - SQL Server Code

Asked

Viewed 193 times

0

I made this code for SQL Server to select how many times the driver "Asdovolante" came first in the first half of 2017. But it doesn’t work. What may be wrong?

SELECT P.Data, Nm.Nome, epp.PosicaoFinal
FROM Prova P, Piloto Nm, EquipaParticipaProva epp
WHERE epp.PosicaoFinal = (SELECT PosicaoFinal FROM EquipaParticipaProva where PosicaoFinal = 1)
HAVING Nm.Nome ='AsdoVolante' AND P.Data BETWEEN '2017-01-01' AND '2017-06-30';

3 answers

0

You have to first check which error is displaying.

Anyway, try the select below: SELECT P.Data, Nm.Name, Epp.Posiofinal FROM Prova P, Piloto Nm, Equipaparticipaprova Epp WHERE Epp.Posicaofinal = 1 AND Nm.Name ='Asdovolante' AND P.Date BETWEEN '2017-01-01' AND '2017-06-30';

0

SELECT P.Data, Nm.Nome, epp.PosicaoFinal
FROM Prova P, Piloto Nm, EquipaParticipaProva epp
WHERE epp.PosicaoFinal = (SELECT epp.PosicaoFinal FROM EquipaParticipaProva where epp.PosicaoFinal = 1)
HAVING Nm.Nome ='AsdoVolante' AND P.Data BETWEEN '2017-01-01' AND '2017-06-30';
  • @Eliasventura Thank you for your reply but the code does not work :(

  • @Tiagos Elias’s code didn’t work

0


You can obtain such information by linking the information with JOIN and restricting in WHERE:

SELECT Nm.Nome,
       COUNT(epp.PosicaoFinal) AS quantidade
  FROM Prova P
       INNER JOIN EquipaParticipaProva epp ON epp.IdProva = P.IdProva
       INNER JOIN Piloto Nm ON epp.IdPiloto = epp.IdPiloto
 WHERE epp.PosicaoFinal = 1
   and Nm.Nome = 'AsdoVolante'
   and P.Data BETWEEN '2017-01-01' AND '2017-06-30';
 GROUP BY Nm.Nome

Browser other questions tagged

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