1
I tried using the following query in my database:
SELECT MAX(COUNT(DISTINCT c.unique_carrier))
FROM companhia_aerea c, avioes4 a, ponte2 v
WHERE c.unique_carrier = a.UniqueCarrier AND a.TailNumber = v.TailNumb AND V.DepDelay > 0;
This query returns me the following error
mysql error code 1111. invalid use of group Function.
Can anyone tell me how I can get around this problem? The structure of the tables is as follows:
CompanhiaAerea (unique_carrier PK, descricao);
Avioes (TailNumber PK, IDModelo FK, IDTipo_licenca FK, unique_carrier FK, IDtipoAviao FK, IDTipo_Motor FK, data_registo, estado, ano);
Voo (IDvoo PK, codigoCancelamento FK, Tail Number FK, iata_origem FK, iata_destino FK, Datavoo, Hora_partida_real, Hora_partida_prevista, Hora_chegada_real, Hora_chegada_prevista, FlightNum, AtualElapsedTime, TempoVoo, distancia, DepDelay, cancelado)
What is the structure of the 3 tables?
– Guilherme Nascimento
i would try this: SELECT MAX(SELECT COUNT(DISTINCT c.unique_carrier) FROM compaia_aerea c, avioes4 a, ponte2 v WHERE c.unique_carrier = a.Uniquecarrier AND a.Tailnumber = v.Tailnumb AND V.Depdelay > 0);
– Adir Kuhn
So that the MAX, in this case?
– cantoni
The database is about flights. I want to know which airline (unique_carrier) has the most delays in departure (Depdelay). Hence the "MAX(COUNT".
– Pedro Cunha
A estrutura das tabelas é a seguinte: 
 CompanhiaAerea(unique_carrier PK, descricao); 

Aviaoes4 (TailNumber PK, IDModelo FK, IDTipo_licenca FK, unique_carrier FK, IDtipoAviao FK, IDTipo_Motor FK, data_registo, estado, ano); 

 Voo (IDvoo PK, codigoCancelamento FK, Tail Number FK, iata_origem FK, iata_destino FK, Datavoo, Hora_partida_real, Hora_partida_prevista, Hora_chegada_real, Hora_chegada_prevista, FlightNum, AtualElapsedTime, TempoVoo, distancia, DepDelay, cancelado)
– Pedro Cunha
@Pedrocunha, check it out: you are doing MAX on top of COUNT(DISTINCT c.unique_carrier). This adds nothing, because COUNT will return only one number and you are giving MAX on it, IE, will return itself. By your comment, the SQL you need is another. Depdelay is INT?
– cantoni
What is the complete structure of the 3 tables? Edit the question and post the code.
– Guilherme Nascimento
@Cantoni Depdelay has numerical values. In the case where the flight instead of delay is anticipated for example 5 minutes what appears in the data is "-5". I do not have as INT because I have 3 million lines with the NA value, for cases where there is no information of the duration of the delay. That’s why I can sweep...
– Pedro Cunha