Question

Hi all I am trying to aggregate the number of searches that clients are doing. I currently have this working for 1 day. I would also like to put in a column for searches for that week, month, year and total

    USE live_travelcoglog; 
    SELECT lu.Name, lu.UID, IFNULL(l.AgentId, 'CP Total') AS "CP", COUNT(*) AS   "DateTotal", MAX(l.Submitted) AS "LastSearchTime" 
    FROM logs l INNER JOIN live_travelcog.users lu ON l.ChannelPartnerId = lu.CustId 
    WHERE Submitted BETWEEN '2014-04-23 00:00:00' AND '2014-04-23 23:59:59' 
    AND l.MessageType = 'COG_HotelAvail_RS' 
    GROUP BY lu.Name, l.AgentId ASC WITH ROLLUP;

Search Results

Now I can run the queries for the different values that I am after but I am sure there is a nicer way that they can all be grouped together. If someone could kindly point me in the right direction it would be greatly appreciated.

Thanks

Daz

Was it helpful?

Solution

Is this the sort of thing you were looking for?

USE live_travelcoglog; 
SELECT
    lu.Name,
    lu.UID,
    IFNULL(l.AgentId, 'CP Total') AS "CP",
    SUM(Submitted BETWEEN '2014-04-23 00:00:00' AND '2014-04-23 23:59:59') AS DateTotal,
    SUM(Submitted BETWEEN '2014-04-17 00:00:00' AND '2014-04-23 23:59:59') AS WeekTotal,
    SUM(Submitted BETWEEN '2014-04-01 00:00:00' AND '2014-04-23 23:59:59') AS MonthTotal,
    MAX(l.Submitted) AS "LastSearchTime" 
FROM logs l
INNER JOIN live_travelcog.users lu
    ON l.ChannelPartnerId = lu.CustId 
WHERE
    l.MessageType = 'COG_HotelAvail_RS'
GROUP BY
    lu.Name,
    l.AgentId ASC
WITH ROLLUP;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top