|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:26 PM
Points: 1,132,
Visits: 663
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 2:43 AM
Points: 2,778,
Visits: 471
|
|
For that query to work it should be grouped by salescategory, salesperson, otherwise you will get this error when running the query
Columns salescategory, salesperson are invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 11:22 PM
Points: 1,079,
Visits: 1,145
|
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 11, 2010 2:15 AM
Points: 327,
Visits: 364
|
|
i think this the group by was left by mistake ...
if we over look that group by then the option 3 is the right answer and thats pretty much fineee...
Mithun
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 2:19 AM
Points: 2,018,
Visits: 4,915
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 4:30 PM
Points: 5,235,
Visits: 7,038
|
|
Others have already pointed out the missing GROUP BY clause, so I'll skip that and limit myself to commenting the non-portable date format used. On many non-US systems, the date '1/31/09' will cause an error message to pop up. The correct format would be: BETWEEN '20090101' AND '20090131' And if the version is SQL2005 or less, or if it's SQL2008 but the data type is not "date" but one of the formats that include a time component as well, then it should even be
WHERE salesdate >= '20090101' AND salesdate < '20090201' because otherwise all sales made after Jan 31st, 0:00 will be excluded.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Wednesday, January 02, 2013 12:15 PM
Points: 1,443,
Visits: 711
|
|
| I don't think that query will work without a group by?
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Yesterday @ 10:15 AM
Points: 634,
Visits: 872
|
|
Poor (non-existent?) QA on this question. Unexpected from this site.
And what about the role of sales_category? The results of the query will also reflect the 'performance' of the sales_category, whatever that is.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, April 19, 2011 7:31 AM
Points: 2,832,
Visits: 5,316
|
|
I too selected the most accurate, albeit incomplete, answer.
dmw (3/18/2009) Poor (non-existent?) QA on this question. Unexpected from this site.
I couldn't agree more but I'm sure with the volume of questions that are sorted through to ultimately be posted, a clunker is going to get through every now and then. Maybe we've become so spoiled by the overall high quality of the site and the information provided here that even some of us "gurus-in-training" are actually learning something which allows us to catch things like this easier/faster????
-- You can't be late until you show up.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 7:19 AM
Points: 1,562,
Visits: 1,716
|
|
dmw (3/18/2009) ...And what about the role of sales_category? The results of the query will also reflect the 'performance' of the sales_category, whatever that is.
This is the part that really bothers me. OK, so they forgot the GROUP BY, but if we are grouping by sales_category but the question asks for total sales, we haven't really satisfied the requirements have we?
|
|
|
|