I have this Olympics Dataset which i imported on PostgreSQL database. I want to Create table using select statement and somemore is there. But I'm getting this error:
ERROR: column foo.age does not exist LINE 17: (case when foo.Age=NULL then foo.Age=26 else foo.Age end... ^ HINT: Perhaps you meant to reference the column "ae.age". SQL state: 42703 Character: 628
what I indent to do is:
- change the type of column age,height,weight
- Take the above data and join it with another query where I want to replace NULL value
- create new table using above two data. all this in one go. I still new to this database, I actually did it in SQLite and it worked fine but here it wont work . If you have any other way to do this please tell me. Thank You! Here is my code :
CREATE TABLE Female_participants AS
SELECT DISTINCT
ae.id AS Player_id,
ae.Name,
( /* Here what i want to do is im thinking like foo table which i joined to this table is giving me
(this and following column where i want to replace NULL values) age,weight and height as int,float,float */
CASE
WHEN/*foo.age suppose to be column from foo table which is casted to int*/
foo.Age = NULL
THEN
foo.Age = 26
ELSE
foo.Age
END
)
AS Age ,
(
CASE
WHEN/*foo.height suppose to be float*/
foo.height = NULL
THEN
FLOOR(AVG(foo.height))
ELSE
foo.height
END
)
AS Height,
(
CASE
WHEN /*foo.Weight suppose to be float*/
foo.weight = NULL
THEN
FLOOR(AVG(foo.weight))
ELSE
foo.weight
END
)
AS weight, City, Team AS Country
FROM
athlete_events ae
INNER JOIN
(
SELECT DISTINCT
id,
/*Here i want to convert the dtype from TEXT to int or float*/
CAST(age AS INT) thag,
CAST(height AS FLOAT) AS thht,
CAST(weight AS FLOAT) AS thwt
FROM
athlete_events /* i read on https://www.postgresqltutorial.com/.. that i can self-join table */
)
AS foo /*Joining this table on id*/
ON foo.id = ae.id
GROUP BY
id,
name