Ask Your Question
4

How to calculate the total of all fields for the car ID that exists in PostgreSQL?

asked 2021-06-25 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-10-23 08:00:00 +0000

scrum gravatar image

Assuming you have a table named "cars" with columns "car_id" and "price", you can use the following query to calculate the total price for a specific car ID:

SELECT SUM(price) as totalprice FROM cars WHERE carid = [insert car ID here];

If you want to calculate the total price for all car IDs, you can use the following query:

SELECT carid, SUM(price) as totalprice FROM cars GROUP BY car_id;

This will provide a list of car IDs and their corresponding total prices.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-25 11:00:00 +0000

Seen: 13 times

Last updated: Oct 23 '22