Question

I want write a MySQL query to get the number of customers who have made at...

I want write a MySQL query to get the number of customers who have made at least one purchase in each group (gender, education), I know how to do with two seperate query. but is that possible to get one query with the column like:

gender | counts | education | counts

The first 5 rows of each table looks like this:

customers

customer_id | first_name | last_name | state | birthdate | education | gender | date_account_opened

50 | Audrey | Osborn | CA | 1939-03-09 | Partial High School | M | 2010-06-03 |
100 | Mary | Hunt | CA | 1946-12-14 | Partial High School | F | 2007-08-06 |
150 | Mary | McCormick | WA | 1946-05-06 | High School Degree | F | 2008-11-06 |
200 | Pamela | Yates | CA | 1994-06-13 | Partial College | F | 2009-07-08 |
250 | Louis | McGrath | OR | 1936-03-25 | High School Degree | M | 2010-06-20

sale:

product_id | store_id | customer_id | promotion_id | store_sales | store_cost | units_sold | transaction_date

758 | 7 | 1150 | 0 | 12.7600 | 4.0832 | 4.0000 | 2015-01-05 |
498 | 7 | 1150 | 0 | 5.1000 | 2.2440 | 2.0000 | 2015-01-05 |
72 | 7 | 3850 | 0 | 13.7000 | 5.7540 | 5.0000 | 2015-01-10 |
942 | 7 | 3850 | 0 | 9.3600 | 4.2120 | 4.0000 | 2015-01-10 |
1258 | 7 | 3850 | 0 | 2.4400 | 1.1468 | 4.0000 | 2015-01-10

Thanks!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

create table customers (

customer_id varchar(6) primary key,

first_name char(15),

last_name char(15),

state char(15),

birthdate date,

education varchar(40),

gender char,

date_account_opened date

);

insert into customer

values('50', 'Audrey', 'Osborn', 'CA', '1939-03-09', 'Partial High School', 'M', '2010-06-03');

insert into customer

values('100', 'Mary', 'Hunt', 'CA', '1946-12-14', 'Partial High School', 'F', '2007-08-06');

insert into customer

values('150', 'Audrey', 'McCormick', 'WA', '1946-05-06', 'High School Degree', 'F', '2008-11-06');

insert into customer

values('200', 'Pamela', 'Yates', 'CA', '1994-06-13', 'Partial College', 'F', '2009-07-08');

insert into customer

values('250', 'Louis', 'McGrath', 'OR', '1936-03-25', 'High School Degree', 'M', '2010-06-20');

create table sale (

product_id varchar(6),

store_id varchar(6),

customer_id varchar(6) references customer(customer_id),

promotion_id varchar(6),

store_sales number(2,4),

store_cost number (1,4),

units_sold number(1,4),

transaction_date date

);

insert into sale

values('758', '7', '1150', '0', 12.7600, 4.0832, 4.0000, '2015-01-05');

insert into sale

values('498', '7', '1150', '0', 5.1000, 2.2440, 2.0000, '2015-01-05');

insert into sale

values('72', '7', '3850', '0', 13.7000, 5.7540, 5.0000, '2015-01-10');

insert into sale

values('942', '7', '3850', '0', 9.3600, 4.2120, 4.0000, '2015-01-10');

insert into sale

values('1258', '7', '3850', '0', 2.4400, 1.1468, 4.0000, '2015-01-10');

select count(customer_id)

from customers, sale

where customers.customer_id=sale.customer_id AND sum(store_sales)>0;

Add a comment
Know the answer?
Add Answer to:
I want write a MySQL query to get the number of customers who have made at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write MySQL query statements for the questions below including the output that proves the accuracy of...

    Write MySQL query statements for the questions below including the output that proves the accuracy of your solution. Your answers should be stored in a text file that captures your interaction with MySQL. 1. Find the movieID, title, year and DVDPrice of all movies where the DVD-Price is equal to the discountPrice. 2. Find the actorID, lastName, firstName, middleName, and suffix of all actors whose middleName is not NULL. 3. Suppose you remember a movie quote as “Play it again,...

  • DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS orders; DROP TABLE IF EXISTS order_details; DROP...

    DROP TABLE IF EXISTS customers; DROP TABLE IF EXISTS orders; DROP TABLE IF EXISTS order_details; DROP TABLE IF EXISTS items; DROP TABLE IF EXISTS artists; DROP TABLE IF EXISTS employees; -- create tables CREATE TABLE customers (    customer_id INT ,    customer_first_name VARCHAR(20),    customer_last_name VARCHAR(20) NOT NULL,    customer_address VARCHAR(50) NOT NULL,    customer_city VARCHAR(20) NOT NULL,    customer_state CHAR(2) NOT NULL,    customer_zip CHAR(5) NOT NULL,    customer_phone CHAR(10) NOT NULL,    customer_fax CHAR(10),    CONSTRAINT customers_pk...

  • Complete Task 4, 5, 6 Instructions Page 3 of 3 query.sql 1 -- Write your query...

    Complete Task 4, 5, 6 Instructions Page 3 of 3 query.sql 1 -- Write your query below and then click "Run Query" to execute it. To save multiple queries, click the "+" icon above. VE Task 4: </> The InstantRide User Satisfaction team is a core team for Instant Ride, and they focus on increasing the customer satisfaction. They want to learn the travel time for each ride in the system. You need to return the USER_ID, and the TRAVEL_TIME...

  • Question 1.Write a SQL statement for each of the following questions based on the above tables...

    Question 1.Write a SQL statement for each of the following questions based on the above tables (50 Points). 1) Create “Enrollment” table. 2) Change the credits of “Database” course from 2 to 3. 3) List the course titles (not Course_No) and grades John Doe had taken. 4) Calculate average of Café Balance, and name new field as Average Balance. 5) Create a roster for “Database” course (list student ID, last name, first name, major, and status for each student enrolled...

  • Seeking help/ explanation for a SQL question. 1.) How many different customers have made orders? Tables: CLOTHES ClOID, Type, Brand, Descript, Matrial, MadeInCountry, Size, Price, SID, POID) CUSTOMER...

    Seeking help/ explanation for a SQL question. 1.) How many different customers have made orders? Tables: CLOTHES ClOID, Type, Brand, Descript, Matrial, MadeInCountry, Size, Price, SID, POID) CUSTOMER (CustID, Cname, Cbirthdate, Cemail, Cstreet, Ccity, Cstate, Czip, CreditCard, CsignupDate) ORDER SHIPMENT (OrderShipiD, Ship:D, Po:D) PURORDER (POID, PurchaseDate, Shipoption, Quantity, CustID) SHIPMENT (ShipID, TrackingNum, Shipstreet, Shipcity, Shipstate, Shipzip, EstimateDeliveryDate, CustID) SUPPLIER (SID, Sname, Sstreet, scity, Sstate, Szip, Slicense) E-R Diagram: Implementation Model Quantity CLOTHES H SUPPLIER CUSTOMER Places 여 PURORDER Contains POID...

  • please answer these queries. 1. List the artist name of the artists who do not have...

    please answer these queries. 1. List the artist name of the artists who do not have a webaddress and their leadsource is “Directmail” 2. List the names of members in the artist called 'Today'. 3. Report the total runtime in minutes FOR EACH album in the Titles table. 4.List the firstname, lastname of members who are represented by the salesperson “Lisa Williams” 5.List EACH salesperson’s firstname along with the number of Members that EACH SalesPerson represents. DROP TABLES IF EXISTS...

  • Connect to mySQL DBMS, open a SQL script file, navigate to CityJail.sql file and execute it...

    Connect to mySQL DBMS, open a SQL script file, navigate to CityJail.sql file and execute it to create tables and populate with the supplied data. If there are any errors in the script fix them. It is your job to find the errors and correct them. This is important. You will need correct data for future exercises in this module. Then answer all questions. Write the answer below each question then take screen shot of the result. This script builds...

  • please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you...

    please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you are going to write a program to represent various types of packages offered by package-delivery services. You need to create an inheritance hierarchy to represent various types of packages with different shipping options and associated costs. The base class is Package and the derived classes are FlatRatePackage and OvernightPackage. The base class Package includes the following attributes: • Sender information: senderName (string), senderAddress (string),...

  • I used easybib for my paper and got a response this is not in apa format....

    I used easybib for my paper and got a response this is not in apa format. Can you tell me why? Introduction The purpose of this project is to conduct a community assessment and apply the nursing process to an identified priority community health problem in Lynn, Massachusetts. Lynn is located in Essex County. It borders Lynnfield, Nahant, Peabody, Revere, Salem, Swampscott, and Saugus, MA. Lynn, MA has a population of 92,074 people with a median age of 33 (McGillicuddy,...

  • 1). The retirement benefit of the Social Security program is considered a progressive benefit with a...

    1). The retirement benefit of the Social Security program is considered a progressive benefit with a regressive financing scheme. (1) How is the Social Security benefit progressive? (2) How is its financing scheme regressive? 2). One of the main goals of the ACA (Patient Protection and Affordable Care Act of 2010, aka Obamacare) was to provide affordable health care to the uninsured. 1. What were the THREE primary pieces of the law that were meant to provide coverage for everyone...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT