Question

Please see the table structure below:

-- Table structure for table `station_listing`
CREATE TABLE IF NOT EXISTS `station_listing`(
  `id` bigint(11) NOT NULL AUTO_INCREMENT,
  `lid` bigint(11) NOT NULL,
  `cid` bigint(11) NOT NULL,
  `name` varchar(300) NOT NULL,
  `type` enum('homeservices','restaurants') NOT NULL,
  `location` varchar(300) NOT NULL,
  `stationID` varchar(300) NOT NULL,
  `claimed` tinyint(1) NOT NULL,
  `closed` tinyint(1) NOT NULL,
  `reviewcount` int(6) NOT NULL,
  `rating` decimal(10,1) NOT NULL,
  `city` varchar(300) NOT NULL,
  `categories` varchar(300) NOT NULL,
  `dealcount` int(6) NOT NULL,
  `result_month` varchar(10) NOT NULL,
  `updated_date` date NOT NULL,
  PRIMARY KEY (`id`),
  KEY `stationID` (`stationID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

-- Dumping data for table `station_listing`
INSERT INTO `station_listing`(
   `id`, `lid`, `cid`, `name`, `type`, `location`,
   `stationID`, `claimed`, `closed`, `reviewcount`, `rating`, `city`,
  `categories`, `dealcount`, `result_month`, `updated_date`
) VALUES (
   310837, 115, 151, 'Apartment Building', 'homeservices', 'West Hollywood',
  'apartment-building-los-angeles', 0, 0, 1, '1.0', 'Los Angeles',
  'apartments', 0, 'Jan', '2014-01-15'
), (
  314, 4, 1, 'King of Shawarma', 'restaurants', 'Calgary',
  'king-of-shawarma-calgary-2', 0, 0, 0, '0.0', 'Calgary', 
  'afghani,halal,falafel', 0, 'Jan', '2014-02-14');

I have a table which consist of details of different business from stations, which are updated every month.

stationID will be updated once in every month with its parameters.

I need to get stationIDs which are common for a selected range of months.For example If I select a range from Jan to Mar,this should fetch all the stations which are common for moths JAn,Feb And MAr.

We tried GROUP BY to group all the stations which appears for the months.

I am facing the following issues,

When I try a query like:

  SELECT stationID 
    FROM station_lisitng 
GROUP BY `stationID``

I am getting the whole list of stationIDs

But when trying to fetch multiple columns, like:

SELECT id, stationID FROM station_lisitng GROUP BY `stationID`;

We are getting and phpMyAdmin Error as 'Showing 0 to -1 results' and we are neither getting the results nor its count.

Our table consist of a large number of entries( 1 million), and we doubt grouping this is making the trouble. Along with there are station IDs with special characters too!

stationID column is indexed and its the only identifiable entity for each station.

SELECT id, stationID FROM station_lisitng GROUP BY `stationID` LIMIT 0,900000`

The above works but consuming lot of time.

It would be great, if you could help us to group this table with stationIDs.

We tried the following query, and we are not satified with its performance:

SELECT `stationID`,
       name,
       lid,
       cid,
       type,
       location, 
       COUNT(*) c 
FROM `yc_biz_listing` 
WHERE DATE_FORMAT(`updated_date`, '%m %Y') BETWEEN '01 2014' AND '03 2014' 
GROUP BY `yelpID` HAVING c = 3

Any help will be highly appreciated. Thanks in advance.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top