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

  • SEARCH
  • Home
  • 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 8805637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:55:07+00:00 2026-06-14T01:55:07+00:00

I have a basic table named customer: CustId Name AB1 George Arkin AB2 Indiana

  • 0

I have a basic table named customer:

CustId Name
AB1    George Arkin
AB2    Indiana James
AB3    Michael Anjelo

and another table named booking:

CustId FlightId Price
AB1    FL134    43.00 
AB1    FL122    21.00
AB1    FL134    49.00
AB1    FL122    48.00  
AB2    FL291    40.00  
AB2    FL291    29.00  
AB2    FL293    22.00  
AB2    FL862    56.00  
AB2    FL862    12.00  
AB2    FL293    99.00  
AB3    FL900    100.00  

Now what I’d like to do is join both tables. I would then like to calculate how many flights a single person has booked (displaying all persons) and I would also like for each person the have a total price next to it adding up the total of each price they have paid. So far I came up with this:

SELECT C.CustId, C.Name, COUNT(DISTINCT B.FlightId) AS "NumberOfTicketsPurchased"
,      SUM(DISTINCT B.Price) AS "TotalPrice"
FROM customer C, booking B

But I only get one result and the total price and count is not accurate.

P.S this is an example table for something I am practising in my own time to prepare for Data Management next Semester.

  • 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-14T01:55:08+00:00Added an answer on June 14, 2026 at 1:55 am

    You will required GROUP BY for using Aggregate functions like Count and SUM.
    Did you try this ?

    SELECT C.CustId, C.CName, Count(B.FlightId) , SUM(B.Price)
    FROM customer C
    LEFT JOIN booking b ON b.CustId = a.CustId 
    GROUP BY  C.CustId
    

    EDIT

    SELECT C.CustId, C.CName, Count(B.FlightId) , SUM(B.Price) as 'price'
    FROM customer C
    INNER JOIN booking b ON b.CustId = a.CustId 
    GROUP BY  C.CustId
    HAVING price > 75
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a customer table in the db that stores the name, address etc,
I have a basic table that looks like the following: SQL> desc comments Name
I have a mysql table named category. the basic structure looks like this- ------
I have a very basic Table structure to be placed in middle/center of the
I have a fairly basic data.table in R, with 250k rows and 90 columns.
I have a very basic mysql table called memberships, that tracks which people belong
I have a basic string with holds a html table. The table looks like
I have this table, which can be seen as a basic custom gantt chart:
I have a messaging system (very basic) that has a table like this: **MESSAGE_ID**
I'm working on a very basic shopping cart system. I have a table items

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.