Question

In using a database created from this model, which of the following SQL queries would give us a list of customers who have daily deposit transactions (deposit is a transaction type) totaling $10,000 or more across all of their accounts (i.e., this is a total across all accounts of a customer, not per account). Include in this list the Customer ID and name, and the dates and their respective daily total.

Consider the following physical entity-relationship model: Customers Addresses Merchants PK mer_id th THPK cust_id FK add id

SELECT c.cust_id, c.cust_name, DATE(t.tran_date), SUM(t.tran_amount) AS daily_total
FROM Customers c
   JOIN Accounts a 
   JOIN Transactions t 
   JOIN Tran_Types tt 
WHERE tt.type = 'deposit'
GROUP BY c.cust_id, c.cust_name, DATE(t.tran_date)
HAVING daily_total >= 10,000;
SELECT c.cust_id, c.cust_name, DATE(t.tran_date), t.tran_amount AS daily_total
FROM Customers c, Accounts a, Transactions t, Tran_Types tt
WHERE tt.type = 'deposit'
  AND c.cust_id = a.cust_id
  AND a.acc_number = t.acc_number
  AND tt.type_id = t.tran_type_id
  AND daily_total >= 10,000;
SELECT c.cust_id, c.cust_name, DATE(t.tran_date), t.tran_amount AS daily_total
FROM Customers c, Accounts a, Transactions t, Tran_Types tt
WHERE tt.type = 'deposit'
  AND c.cust_id = a.cust_id
  AND a.acc_number = t.acc_number
  AND tt.type_id = t.tran_type_id
GROUP BY c.cust_id, c.cust_name, DATE(t.tran_date)
HAVING daily_total >= 10,000;

None of the above.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
SELECT c.cust_id, c.cust_name, DATE(t.tran_date), SUM(t.tran_amount) AS daily_total
FROM Customers c
   JOIN Accounts a 
   JOIN Transactions t 
   JOIN Tran_Types tt 
WHERE tt.type = 'deposit'
GROUP BY c.cust_id, c.cust_name, DATE(t.tran_date)
HAVING daily_total >= 10,000;

B is wrong as t.tran_amount is not the total sum of amount in all accounts of the customer

C is wrong as SUM() function is not used with Group by .

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
In using a database created from this model, which of the following SQL queries would give...
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
  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query to display products purchased by customers in Germany that were not purchased by customers in the US. Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode Country Phone char(5) varchar(40) varchar(30) varchar(30) varchar(60) varchar(15) varchar(15) varchar(10) varchar(15) varchar(24) varchar(24) Order Details Orders PK OrderID int FK CustomerlD char(5) FK Employeeld int...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders wants to make sure that all orders are shipped within 10 days. Display any orders that were not shipped within 10 days. Include the OrderID, the OrderDate, and the number of days it took before the order was shipped. Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders has decided to increase their retail prices. Write a query that shows the product name, the current price, and the new price. Make sure the new price is listed to 2 decimal points. Follow below guidelines on new retail price: a.         If the category is beverages or dairy products, increase the price by...

  • The owner of the B&B would like to know how much each room contributes to total...

    The owner of the B&B would like to know how much each room contributes to total revenues. In this regard, she would like a list of rooms (room ID and room name), and how much revenue each room brought in for 2019 (even including rooms that did not bring in any revenue; i.e., they weren't booked in 2019). Room revenue (for a given booking) are found in the total field in Bookings. You only need to consider bookings where check-in...

  • Questions are based on the Northwind database. a. A data dictionary (Excel file) that describes each...

    Questions are based on the Northwind database. a. A data dictionary (Excel file) that describes each of the tables. (Attached in question) b.    Write good, clean SQL that answers the following questions. c.     Separate your queries as I have done in the following example. End each query with a semicolon (;) and insert the word "go" between each query. Queries can span multiple lines if required. Select CustomerID from Customers; go Select Count(*) from Employees; go Select max(productID) from Products; 18. Produce...

  • im currently working on an sql database homework for a fundamentals class but im not too...

    im currently working on an sql database homework for a fundamentals class but im not too sure if my results are alright and would like to compare results, the assignment is as follows: O4pk,fk evaluate de data models, the specifications and table contents: equipment_tb Assigned_Equipment_tb workers_tb pk serial_number int pk,fk serial number int pk worker_id int, Surrogate brand char(10) worker id int Lastname char(100) model char(15) assigned_date date Firstname char(50) processor char(15) department int processor_velocity number (3,2) email char(200) memory...

  • SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address...

    SQL queries and procedures TABLE: Employees Business Rules: EmployeeID is defined as the primary key. Address has been denormalized to include City and State for performance reasons. DeptNbr is a foreign key that references DeptNbr in the Department table Manager is a foreign key that references EmployeeID in the Employees table Data Structure: (EmployeeId, LastName, FirstName, Street, City, State, Zip, DateOfHire, DateOfBirth, JobTitle, Salary, DeptNbr(fk), Manager(fk)) TABLE: Department Business Rules: DeptNbr is defined as the primary key. Data Structure: (DeptNbr,...

  • Given the following schema: I would like to know the SQL queries to: 1. Total up...

    Given the following schema: I would like to know the SQL queries to: 1. Total up the number of checkouts made on each month of the year. Then print the month (spelled out completely) and the total number of corresponding checkouts next to it. That is, print "January" and total number of checkouts made in January, and so on. 2. Show the furniture styles that are checked-out on Sundays only. That is, none of the furniture in that style must...

  • Write Ten SQL SELECT statements to query the STUDENT schema you created for practice lab. 4....

    Write Ten SQL SELECT statements to query the STUDENT schema you created for practice lab. 4. List all cities that have 10 or more students and instructors combined. Show city, state, number of student residents, number of instructor residents, and total student/instructor residents in that city. Sort by total in descending order. 5. List the instructor id and name of the instructors that teach fewer than 10 sections. 7. Find how many students are enrolled in sections taught by Todd...

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