It seems as if once I use Group By in my query I begin returning errors in my where clause.

SELect Rtrim(riders.firstName)||' '||rtrim(riders.lastname) AS Rider_Name, teams.teamname, Rtrim(agents.firstName)||' '||rtrim(agents.lastname) AS Agent_Name
FROM Riders, teams, agents, participation, races
Where teams.teamID = riders.teamID
and agents.agentID = riders.agentID
and participation.riderID = riders.riderid
and races.raceid = participation.raceid
and races.RaceDate Between '01-Apr-2008' and '30-Apr-2008'

That returns the results I need, but I need to eliminate any duplicates so i've done

Group BY Rtrim(riders.firstName)||' '||rtrim(riders.lastname)

and

Group BY participation.riderID

and

Group By rider.riderID

and those were my best guesses. here is the full code.

SQL> SELect Rtrim(riders.firstName)||' '||rtrim(riders.lastname) AS Rider_Name,
teams.teamname, Rtrim(agents.firstName)||' '||rtrim(agents.lastname) AS Agent_Na
me
  2  FROM Riders, teams, agents, participation, races
  3  Where teams.teamID = riders.teamID
  4  and agents.agentID = riders.agentID
  5  and participation.riderID = riders.riderid
  6  and races.raceid = participation.raceid
  7  and races.RaceDate Between '01-Apr-2008' and '30-Apr-2008'
  8  Group BY participation.riderid
  9  ;
SELect Rtrim(riders.firstName)||' '||rtrim(riders.lastname) AS Rider_Name, teams
.teamname, Rtrim(agents.firstName)||' '||rtrim(agents.lastname) AS Agent_Name
             *
ERROR at line 1:
ORA-00979: not a GROUP BY expression
有帮助吗?

解决方案

If you want to eliminate exact duplicate rows, you can just use select distinct:

SELect DISTINCT Rtrim(riders.firstName)||' '||rtrim(riders.lastname) AS Rider_Name,
       teams.teamname, Rtrim(agents.firstName)||' '||rtrim(agents.lastname) AS Agent_Name

Then don't use the group by.

其他提示

I'd recommend using Group By rider.riderID

you just need to add rider.riderID into the fields list

FWIW group by is faster than distinct

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top