February 21, 2014 at 1:41 pm
Team,
I would like to include few columns (varchar and int data types) from same table in below query without adding in group clause, i do not want these column to be group but want to include, please advise.
---------------------------------------------------------------
SELECT count(*) as Qty, CustomerName, [SalesOrder], CONVERT(VARCHAR(10),LogDate,110) FROM [MyLocalDB]
group by Customer , [Sales Order], LogDate
order by LogDate
----------------------------------------------------------------
Thank You
February 21, 2014 at 1:47 pm
ghitpro (2/21/2014)
Team,I would like to include few columns (varchar and int data types) from same table in below query without adding in group clause, i do not want these column to be group but want to include, please advise.
---------------------------------------------------------------
SELECT count(*) as Qty, CustomerName, [SalesOrder], CONVERT(VARCHAR(10),LogDate,110) FROM [MyLocalDB]
group by Customer , [Sales Order], LogDate
order by LogDate
----------------------------------------------------------------
Thank You
What do you mean you don't want to group? Are you saying you don't want to group by those columns? That is what aggregate data does.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 21, 2014 at 1:50 pm
You might want to take a look at the OVER Clause.
February 21, 2014 at 2:12 pm
ghitpro (2/21/2014)
Team,I would like to include few columns (varchar and int data types) from same table in below query without adding in group clause, i do not want these column to be group but want to include, please advise.
Why? What's the final objective you're trying to arrive at that Group By is something to avoid?
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
February 21, 2014 at 3:51 pm
Team,
if i include column without group clause im getting below error...
i want to add one column without using aggregate function but want column data beside aggregate columns....
____________________________________________
Column 'station' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause
___________________________________________________
is their any way i can add column without using aggregate function in aggregate query...
Thank You Guys
February 21, 2014 at 4:02 pm
Two options:
Create another query based on the summary query and the original table. include the column from the original table that you couldn't use in the summary query.
Or
Build the query using windowing functions.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply