Hi guys,
have this procedure set up that produces a count, by customer of requests made.
What i need to do is now factor in another table and make sure that the product_id is only being counted once per day, so if the same dealer makes a requst for info on the same product more than once in one day, then it only counts it as 1.
i.e
same product_id + same day = 1
same product_id + different day = 2 or more
same product_id + different dealer = 2 or more
etc...
what i have so far is as follows (this just counts the Total requests and the total 'getProductDetails', it is the 'getProductDetails' count that needs to change)
The @start and @end can obviously change - so its not as simple looking for one instance of the Product_Id between those dates (as these dates are set to be weekly, monthly etc), so it needs to per day between those dates.
The table i need to join on is Product -
(Product.oltpId = DLog.product_group_id)
..then in the Product table there is a column 'Product_Id' this is what i need to make sure is only ONCE per day etc.
I think the above makes sense...
Any help greatly appreciated - any questions just ask.
Cheers guys.
have this procedure set up that produces a count, by customer of requests made.
What i need to do is now factor in another table and make sure that the product_id is only being counted once per day, so if the same dealer makes a requst for info on the same product more than once in one day, then it only counts it as 1.
i.e
same product_id + same day = 1
same product_id + different day = 2 or more
same product_id + different dealer = 2 or more
etc...
what i have so far is as follows (this just counts the Total requests and the total 'getProductDetails', it is the 'getProductDetails' count that needs to change)
Code:
SELECT
O.oltpId AS Id_Dealer,
COUNT(*) As TotalRequests,
sum(CASE WHEN L.message = 'getProductDetails' THEN 1 ELSE 0 END) AS TotalGetProduct
FROM DLog DL
INNER JOIN Organisation O
ON DL.dealer_id = O.oid
WHERE
L.logTime >= @start
AND L.logTime < @end
AND O.orgType = 0
GROUP BY
O.oltpId
The @start and @end can obviously change - so its not as simple looking for one instance of the Product_Id between those dates (as these dates are set to be weekly, monthly etc), so it needs to per day between those dates.
The table i need to join on is Product -
(Product.oltpId = DLog.product_group_id)
..then in the Product table there is a column 'Product_Id' this is what i need to make sure is only ONCE per day etc.
I think the above makes sense...
Any help greatly appreciated - any questions just ask.
Cheers guys.