Luca
Luca
Explore posts from servers
DTDrizzle Team
Created by Luca on 6/1/2023 in #help
noob help: INSERT with JOIN SQL to Drizzle
Frontend developer dabbling with SQL for the first time in years. With the help of ChatGPT I have the following query which works as intended. How do I construct with Drizzle such that I can supply my values using the .values() method?
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
7 replies