Question

Hello, just need some help with a few MS-SQL queries. I asked these questions recently and recieved multiple errors when trying them out.

Questions:

This is the database that the queries should be written about: Shopltems itemlD itemDescription pnice markup CustomerPurchases CustomerVisits dateVisit ? customerID customerlD dateVisit itemiD visitDuration qty totalDue Customers LcustomerlD firstName lastName mainPhoneNo secondaryPhoneNo email addressLinel addressLine2 isp Profiles t profilelD parentProfilelD profileDescription earlybird assertive CustomerProfiles customerlD profilelD comment

Previous answer to Task 2 that didnt work:

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

It would have been easy if you could have shared the DB details also. Anyway, For TASK 2: you can use the following query


UPDATE Customers set TotalVisits=(select count(CustomerID) from CustomerVisits where Customers.CustomerID=Customervisits.CustomerID group by CustomerID);

I have tested the query on a different database and it is working as you want.

Task 4: Trigger should work something like this:

It needs to automatically update the customers totalvisits column on the basis an update,delete and insertion.

You should look for spelling mistakes if any in the below code because we can't test without the DB here.

create or replace trigger total_visits on CustomerVisits
after INSERT or DELETE or UPDATE as
begin
UPDATE Customers set TotalVisits=(select count(CustomerID)
from CustomerVisits where Customers.CustomerID=customervisits.CustomerID
group by CustomerID);
end;
/

Similarly, Task for totalspent can be completed.

Add a comment
Know the answer?
Add Answer to:
Hello, just need some help with a few MS-SQL queries. I asked these questions recently and...
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
  • Using the database: Write SQL queries for each of the questions below. 1. Find the media...

    Using the database: Write SQL queries for each of the questions below. 1. Find the media type which has 100 or more tracks. Print the name of such media type. Number of rows returned in the result = 3 A) Find the playlists which have one or more tracks that have never been purchased in California (CA). Print the Id, and the name of such playlists. Number of rows returned in the result = 18 B) Find the customers who...

  • Hello, I need help answering all 8 of these questions for my BIS 422 class. I...

    Hello, I need help answering all 8 of these questions for my BIS 422 class. I need the appropriate MySQL script to use for these questions Provide the SQL for the following data requests. Your SQL should be written as a single script that can be pasted into MySQL and run without edits. Make sure you use the proper notation for your comments (see the practice solution for an example of the format). There will be a 5% deduction for...

  • Hi, I'm trying to do my homework for my SQL Server class I keep getting stuck on the questions 1-...

    Hi, I'm trying to do my homework for my SQL Server class I keep getting stuck on the questions 1-5  I found out like how the format need to be I'm just stuck on implanting the code in. Auntie B's Antic ERD CUSTOMER OWNER PEOPLE PeoplelD CustomerSince CHARITY Peopleld FirstName LastName Address City State Zip Phone CellPhone EMail PeopleType CharityID Name Address City State WORKERS PeoplelD HireDate TermDate SSN ip Phone ContactID ORDERS OrderlD OrderDate CustomerlD EmployeelD DONATION DonationID DonationDate...

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