Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
scottw1988
Starting Member
4 Posts |
Posted - 2012-04-02 : 23:21:37
|
| First off, this is a homework assignment. I do not want you to answer the question just give guidance.The question is:Did the store sell more cats or dogs in the first quarter?The ERD used is here: http://jerrypost.com/DBMS/Exercises/Ch04DBExercises.htmlThis is what my current Query looks like:SELECT A.CATEGORY, COUNT(A.ANIMALID) AS COUNTOFANIMALIDFROM ANIMAL A INNER JOIN SALEANIMAL L ON A.ANIMALID = L.ANIMALID INNER JOIN SALE S ON L.SALEID = S.SALEIDGROUP BY A.CATEGORYWhat I need to know is how do I include on the cats or dogs sold in the first quarter. I know i still need to include a where or having statement that reads: WHERE Category ="Dog" or Category ="Cat". I know there is a Quarter function can it be applied here? The query needs to be written so that it can pertain to any year.Scott Williamson |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-03 : 00:13:07
|
quote: First off, this is a homework assignment. I do not want you to answer the question just give guidance.
Finally ! A rare one.click [LIKE]some pointers1. you can use datepart( quarter, <date col> ) to find out the date is in which quarter2. you need to filter out the sales for the 1st quarter. Write that condition in the WHERE clause3. the date is in another table. You will need another join to that table KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|