Group By
-
Monday, January 14, 2013 7:05 AM
Table A
SalesPerson SalesDate SalesValue
James 01 Jan 2013 $100.00
Anderson 01 Jan 2013 $120.00
James 01 Jan 2013 $110.00
Alex 01 Jan 2013 $80.00
James 02 Jan 2013 $105.00
Anderson 02 Jan 2013 $107.00
Result To Show:
SalesPersonCount Date
3 01 Jan 2013
2 02 Jan 2013
All Replies
-
Monday, January 14, 2013 7:10 AM
Try like this....
select COUNT(*) as SalesPersonCount, SalesDate as date from tableA group by SalesDate
-Saurabhhttp://www.linkedin.com/profile/view?id=36482856&trk=tab_pro http://www.experts-exchange.com/M_6313078.html
- Proposed As Answer by Naomi NMicrosoft Community Contributor, Moderator Monday, January 14, 2013 4:19 PM
- Unproposed As Answer by Naomi NMicrosoft Community Contributor, Moderator Monday, January 14, 2013 4:19 PM
-
Monday, January 14, 2013 7:11 AM
Try
select count(salesPerson) SalesPersonCount, SalesDate [Date]
from TableA
group by SalesDate
order by 2;
Many Thanks & Best Regards, Hua Min
- Edited by HuaMin ChenMicrosoft Community Contributor Monday, January 14, 2013 7:11 AM
- Edited by HuaMin ChenMicrosoft Community Contributor Monday, January 14, 2013 7:12 AM
-
Monday, January 14, 2013 7:17 AMThere is duplicate count record on date 01 Jan 2013. The result show 4 person on 01 Jan 2013
-
Monday, January 14, 2013 7:27 AM
SELECT SalesPersonCount = COUNT(DISTINCT salesPerson), SalesDate FROM TableA GROUP BY SalesDate
Krishnakumar S
- Marked As Answer by Giin Sing Monday, January 14, 2013 8:36 AM
-
Monday, January 14, 2013 7:39 AM
There is duplicate count record on date 01 Jan 2013. The result show 4 person on 01 Jan 2013
Try
select count(distinct salesPerson) SalesPersonCount, SalesDate [Date]
from TableA
group by SalesDate
order by 2;
Many Thanks & Best Regards, Hua Min
- Marked As Answer by Giin Sing Monday, January 14, 2013 8:36 AM
-
Monday, January 14, 2013 11:54 PM
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. If you know how, follow ISO-11179 data element naming conventions and formatting rules. Temporal data should use ISO-8601 formats. Code should be in Standard SQL AS much AS possible and not local dialect.
This is minimal polite behavior on SQL forums. Sample data is also a good idea, along with clear specifications.
SELECT sales_date, COUNT (sales_person) AS sales_person_cnt
FROM Sales
GROUP BY sales_date;--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL

