Q:

Mysql query for select data within 5,10 minit and 1,2 hours

I have a two date one is entry_user and exit_user i want display count of number of user spend time in showroom from last 5 minit , last 30 minit and last 1 hours..I want to make this result from mysql query
Please Suggest me to how i do this for display below result
thanks advance
i want result like this
date        visitor_count

5 (minit)     4
10(minit)     10
1(hours)      20

my table example:

A:

Create auxiliary table intervals, and add to this your time intervals in seconds. For example
CREATE TABLE `intervals` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `value` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO `analytics`.`intervals` (`value`) VALUES(0),(300),(600),(1800),(3600);

To display count of user number accordinging to duration of an user activity use following:
SELECT 
  `value` AS `Duration`, COUNT(*) AS `visitor_count`
FROM
  (
  SELECT
    UNIX_TIMESTAMP(exit_user)-UNIX_TIMESTAMP(entry_user) AS `Interval`
  FROM
    YourTable
  ) AS `Calculations` 
  JOIN intervals ON `Calculations`.`Interval` >= intervals.value
GROUP BY intervals.value

If you also want to group users by date of visit, then use
SELECT 
  `Date`, `value` AS `Duration`, COUNT(*) AS `visitor_count`
FROM
  (
  SELECT
    DATE(`entry_user`) AS `Date`,
    UNIX_TIMESTAMP(`exit_user`)-UNIX_TIMESTAMP(`entry_user`) AS `Interval`
  FROM
    YourTable
  ) AS `Calculations` 
  JOIN intervals ON `Calculations`.`Interval` >= intervals.value
GROUP BY `Calculations`.`Date`, intervals.value

