Hi Guys,
I have trawlled the forum but can't find the answer to this Count problem...
I have a querry that results in something like this:
Note: I have used distinct because I don't want to include more than one record for a customer who has bought the same item from the same sales rep on more than one occassion.
the query goes somthing like this...
What I am trying to figure out is how I get an extra row to show me how may items ordered by each customer as follows...
The count would be the result of the rest of the query, therefore cust "456" might have ordered item_id "ff" but because "ff" is not in the query I don't want that included in the output or count.
I hope this makes some sense.
Any ideas?
Cheers,
Kevin.
I have trawlled the forum but can't find the answer to this Count problem...
I have a querry that results in something like this:
Code:
user_id | item_id | is_member | sales_rep
------------------------------------------
123 | aa | Y | bob
123 | bb | Y | bob
123 | cc | Y | bob
456 | aa | N | bill
456 | dd | N | bill
789 | bb | Y | ted
789 | dd | Y | ted
853 | ab | N | fred
853 | dd | Y | fred
Note: I have used distinct because I don't want to include more than one record for a customer who has bought the same item from the same sales rep on more than one occassion.
the query goes somthing like this...
Code:
SELECT distinct customer.user_id user_id,
orders.item_id item_id,
customer.is_member is_member,
customer.sales_rep sales_rep
FROM
( orders
LEFT JOIN customer.user_id = order.user_id)
WHERE (orders.item_id = 'aa' OR
orders.item_id = 'bb' OR
orders.item_id = 'cc' OR
orders.item_id = 'dd')
What I am trying to figure out is how I get an extra row to show me how may items ordered by each customer as follows...
Code:
user_id | item_id | is_member | sales_rep | order_count
----------------------------------------------------------
123 | aa | Y | bob | 3
123 | bb | Y | bob | 3
123 | cc | Y | bob | 3
456 | aa | N | bill | 2
456 | dd | N | bill | 2
789 | bb | Y | ted | 2
789 | dd | Y | ted | 2
853 | ab | N | fred | 2
853 | dd | Y | fred | 2
The count would be the result of the rest of the query, therefore cust "456" might have ordered item_id "ff" but because "ff" is not in the query I don't want that included in the output or count.
I hope this makes some sense.
Any ideas?
Cheers,
Kevin.