Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:39:17+00:00 2026-06-04T11:39:17+00:00

It is a homework, but I can not do alone. 1) List the code

  • 0

It is a homework, but I can not do alone.

1) List the code name, the amount of cars sold and the total profit for resale
for resales who have profit up to $5000.

resale:
cod | name    | city      | state
--------+-----------------+------------+--------
01  | Paraiso | Sao Paulo | SP
02  | Alameda | Taubate   | SP
03  | Cabana  | Macae     | RJ
04  | Santana | Betim     | MG


Automotive:
cod | manufacturer | model      | year | country   | price
--------+------------+-----------------+------+-----------+----------
01  | 01           | Gol        | 2000 | Brasil    | 25000.00
02  | 01           | Golf       | 2005 | Argentina | 39000.00
03  | 04           | Ford Ka    | 1990 | Brasil    | 15000.00
04  | 03           | Corsa Seda | 1995 | Brasil    | 12500.00
05  | 04           | Fiesta     | 2003 | Argentina | 20000.00
06  | 03           | Corsa Seda | 1995 | Argentina | 10000.00
07  | 05           | Palio      | 2002 | Brasil    | 15000.00
08  | 05           | Siena      | 2006 | Brasil    | 26000.00

sale:
customer| resale | automotive | date       | value
---------+---------+-----------+------------+----------
02      | 01     | 03         | 2010-02-05 | 17500.00
04      | 02     | 01         | 2010-01-07 | 28000.00
01      | 03     | 08         | 2010-02-15 | 28000.00
02      | 03     | 02         | 2010-03-12 | 42000.00
03      | 04     | 06         | 2010-02-06 | 11500.00
03      | 02     | 05         | 2010-01-25 | 22100.00
01      | 01     | 04         | 2010-01-21 | 15500.00
03      | 01     | 08         | 2012-02-05 | 17500.00

My SQL:

SELECT automotive.cod, resale.name, COUNT(sale.resale) AS ammount, SUM(sale.value - automotive.price) AS total FROM sale, automotive, resale 
WHERE sale.resale = resale.cod AND automotive.cod = sale.automotive 
GROUP BY sale.resale, automotive.cod, resale.name 
HAVING SUM(sale.value - automotive.price) <= 5000;

I cant do alone, my answer is wrong.

Ps: I’m using PostgresSQL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:39:20+00:00Added an answer on June 4, 2026 at 11:39 am

    You almost had it:

    SELECT r.cod, r.name
         , count(s.resale) AS amount
         , sum(s.value - a.price) AS total
    FROM   sale s
    JOIN   automotive a ON a.cod = s.automotive 
    JOIN   resale r     ON r.cod = s.resale
    GROUP  BY r.cod, r.name 
    HAVING sum(s.value - a.price) <= 5000;
    

    I reformatted your query with table aliases and explicit JOIN syntax to make it more readable.

    Basically, you only need to replace a.cod with r.cod. Looks like a typo. That makes s.resale in the GROUP BY clause redundant, so I removed it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok this is a homework questions, but I cannot find the answer anywhere, not
I know I should do my homework on my own but I simply can't
This is not exactly homework but it is related to my studies: A grammar
well I'm doing this homework but I'm still not viewing the fault... When I
I've got a real problem (it's not homework, you can check my profile). I
This is not an homework. But an practice to understand what are the best
Full disclaimer: this is not really a homework, but I tagged it as such
This is a homework question, I got the basics down, but I can't seem
This IS NOT homework, but it is a practice that the teacher gave us
This is homework, but I need a nudge. I can't find how to sort

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.