first time code help - PostgreSQL help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Viji2021
    New Member
    • Aug 2021
    • 1

    first time code help - PostgreSQL help

    hi,

    I have written code in T-Sql used code converter for PostgreSQL, got below code but it is giving complier error. I have no clue in PostgreSQL so any pointer will be of great help.
    ------------------------------------------------------------------------------------------------------------------------------
    Code:
    select t.team_id, t.team_name,COALESCE(SUM(num_points),0) num_points from 
       (select team_id, [B]host_team, 3 into team_name, num_points [/B]  [I]-----syntax error at or near ","
                                                                                         -----LINE 3:    (select team_id, host_team, 3 into team_name, num_points[/I]
       
       from matches m
       inner join teams t on m.host_team = t.team_id
       where host_goals > guest_goals
       Union All
        select team_id, guest_team,  3 into team_name, num_points
       from matches m
       inner join teams t on m.guest_team = t.team_id
       where guest_goals > host_goals
       Union All 
        select team_id, guest_team,  1 into team_name, num_points
       from matches m
       inner join teams t on m.guest_team = t.team_id
       where guest_goals = host_goals
        Union All 
        select team_id, host_team,  1 into team_name, num_points
       from matches m
       inner join teams t on m.host_team = t.team_id
       where guest_goals = host_goals)
       r
       right outer join teams t on r.team_id = t.team_id
       group by  t.team_id, t.team_name
       order by 1
    Last edited by Banfa; Aug 31 '21, 11:29 AM. Reason: Added code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    That is a long and complicated statement, I would break it down and test smaller parts of it.

    Alternatively rather than translation from T-SQL I would determine what I wanted to do and re-write it directly in postgresql

    Comment

    Working...