MySQL Forums
Forum List  »  Newbie

Unable to Put CTE into A Table
Posted by: Bhima Fairul Rifqi
Date: December 13, 2024 02:15PM

Can anyone help me?

I'm new into SQL and my SQL is MySQL ver 8.0.40.
I'm currently doing a dummy sql project about the NBA and i got a problem.
I made some CTEs and there's one CTE named 'trade_transaction_cte'.
I wanna make a table named "trade_transaction" and insert the trade_transaction_cte into it, but i keep getting error 1064.
Does anyone have the solution?
Very thankful for any solution, advice, and tips

Here's my query

-- Creating table
CREATE TABLE trade_transaction (
indexing INT AUTO_INCREMENT,
player_id VARCHAR(10) NOT NULL,
player VARCHAR(50) NOT NULL,
tm VARCHAR(10) NOT NULL,
PRIMARY KEY (indexing)
)
;

-- Into the CTEs
WITH players_traded AS (
SELECT *
FROM players_average
WHERE tm = 'TOT' AND season = '2024'
),
players_kept AS (
SELECT *
FROM players_average
WHERE player_id NOT IN (SELECT player_id FROM players_traded) AND season = '2024'
),
players_24 AS (
SELECT *
FROM players_traded
UNION ALL
SELECT *
FROM players_kept
),
trade_transaction_cte AS (
SELECT player_id, player, tm
FROM players_average
WHERE player_id IN (SELECT player_id FROM players_traded)
AND season = '2024'
)
INSERT INTO trade_transaction (player_id, player, tm)
SELECT player_id, player, tm
FROM trade_transaction_cte
;

Options: ReplyQuote


Subject
Written By
Posted
Unable to Put CTE into A Table
December 13, 2024 02:15PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.