i have a table with sale_id, date, sales_person_id
i need to find out the sales_person_id's who did 1 sales every month
from jan 2003 and another query who did a sales every quarter.
I need to find out how many sales people (count) made atleast 25 sales
each year from 2003 - 2005VJ,
http://support.microsoft.com/newsgr...n-us&sloc=en-us
AMB
"VJ" wrote:
> i have a table with sale_id, date, sales_person_id
> i need to find out the sales_person_id's who did 1 sales every month
> from jan 2003 and another query who did a sales every quarter.
> I need to find out how many sales people (count) made atleast 25 sales
> each year from 2003 - 2005
>|||This does not have the answers to these questions, but it has what you
need to find the answers.
SELECT sales_person_id,
Months = count(distinct datediff(month, '1 Jan 2003',
sales_date),
Quarters = count(distinct datediff(quarter, '1 Jan 2003',
sales_date),
Y2003 = SUM(CASE WHEN datepart(year,sales_date) = 2003
THEN 1 ELSE 0 END),
Y2004 = SUM(CASE WHEN datepart(year,sales_date) = 2004
THEN 1 ELSE 0 END),
Y2005 = SUM(CASE WHEN datepart(year,sales_date) = 2005
THEN 1 ELSE 0 END)
FROM Sales
GROUP BY sales_person_id
Roy Harvey
Beacon Falls, CT
On 13 Jun 2006 10:59:05 -0700, "VJ" <vishal.sql@.gmail.com> wrote:
>i have a table with sale_id, date, sales_person_id
>i need to find out the sales_person_id's who did 1 sales every month
>from jan 2003 and another query who did a sales every quarter.
>I need to find out how many sales people (count) made atleast 25 sales
>each year from 2003 - 2005|||select sales_person_id, count(sale_id) 'total_sale' into #t1 from lot
where year(start) ='2003' group by artist_id having count(sale_id) >25
select sales_person_id, count(sale_id) 'total_sale' into #t2 from lot
where year(start) ='2004' group by artist_id having count(sale_id) >25
select sales_person_id, count(sale_id) 'total_sale' into #t3 from lot
where year(start) ='2005' group by sales_person_id having count(lot_id)
>25
select #t1.sales_person_id,
sum(#t1.[total_sale]+#t2.[total_sale]+#t3.[total_sale]) from #t1, #t2,
#t3
where #t1.sales_person_id = #t2.sales_person_id
and #t2.sales_person_id = #t3.sales_person_id
group by #t1.sales_person_id
Roy Harvey wrote:
> This does not have the answers to these questions, but it has what you
> need to find the answers.
> SELECT sales_person_id,
> Months = count(distinct datediff(month, '1 Jan 2003',
> sales_date),
> Quarters = count(distinct datediff(quarter, '1 Jan 2003',
> sales_date),
> Y2003 = SUM(CASE WHEN datepart(year,sales_date) = 2003
> THEN 1 ELSE 0 END),
> Y2004 = SUM(CASE WHEN datepart(year,sales_date) = 2004
> THEN 1 ELSE 0 END),
> Y2005 = SUM(CASE WHEN datepart(year,sales_date) = 2005
> THEN 1 ELSE 0 END)
> FROM Sales
> GROUP BY sales_person_id
> Roy Harvey
> Beacon Falls, CT
>
> On 13 Jun 2006 10:59:05 -0700, "VJ" <vishal.sql@.gmail.com> wrote:
>
No comments:
Post a Comment