Jump to content

tweak of query, to correct a slight error in results.


Recommended Posts

SELECT e.id, e.clicks, e.submittedby, DATE_FORMAT( e.submitgmtdatetime, '%Y-%m' ) AS `yrmonth`
FROM sites e
INNER JOIN (
SELECT DATE_FORMAT( submitgmtdatetime, '%Y-%m' ) AS `yrmonth` , MAX( clicks ) AS clicks
FROM sites
GROUP BY `yrmonth` DESC
) AS x ON DATE_FORMAT( e.submitgmtdatetime, '%Y-%m' ) = x.yrmonth
AND e.clicks = x.clicks
WHERE e.submittedby != 'admin'

 

I get these results

 

id clicks submittedby yrmonth

123 407 admin 2008-09

131 414 user1 2008-10

167 420 user2 2008-11

753 334 admin 2008-12

 

 

but i would like to have the results where the 'admin' is not in the resultsbut the next user that is not the 'admin' that has the highest number of clicks.  and for each month.

table structure...

CREATE TABLE IF NOT EXISTS `sites` (
  `id` int(11) NOT NULL auto_increment,
  `submitgmtdatetime` datetime NOT NULL default '0000-00-00 00:00:00',
  `clicks` int(11) NOT NULL default '0',
  `confirmed` char(1) NOT NULL default '0',
  `submittedby` text NOT NULL,
  `confirmedby` text NOT NULL,
  KEY `id` (`id`)
)

That's weird, I get these results:

[pre]

id    clicks    submittedby    yrmonth

167 420      user2           2008-11

131 414      user1           2008-10

[/pre]

 

Using your structure

CREATE TABLE `sites` (
  `id` int(11) NOT NULL auto_increment,
  `submitgmtdatetime` datetime NOT NULL default '0000-00-00 00:00:00',
  `clicks` int(11) NOT NULL default '0',
  `confirmed` char(1) collate latin1_german2_ci NOT NULL default '0',
  `submittedby` text collate latin1_german2_ci NOT NULL,
  `confirmedby` text collate latin1_german2_ci NOT NULL,
  KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=754 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=754 ;

and this test data(copied from your output you said you got)

INSERT INTO `sites` VALUES (123, '2008-09-01 00:00:00', 407, '0', 'admin', '');
INSERT INTO `sites` VALUES (131, '2008-10-01 00:00:00', 414, '0', 'user1', '');
INSERT INTO `sites` VALUES (167, '2008-11-01 00:00:00', 420, '0', 'user2', '');
INSERT INTO `sites` VALUES (753, '2008-12-01 00:00:00', 334, '0', 'admin', '');

I'm using Mysql 5.0

but i would like to have the results where the 'admin' is not in the resultsbut the next user that is not the 'admin' that has the highest number of clicks.  and for each month.

Isn't this continued for another topic???

 

And I have no idea what you mean.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.