MySQL: SUM in WHERE clause

Posted by checcco on Stack Overflow See other posts from Stack Overflow or by checcco
Published on 2010-06-07T11:18:01Z Indexed on 2010/06/07 11:22 UTC
Read the original article Hit count: 157

Filed under:

Hi guys, I've got this table

CREATE TABLE `subevents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT NULL,
  `content` text,
  `class` tinyint(4) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM

Each row can have a different value in the 'class' field.

I'd like to select any number of rows, ordered randomly, as long as the sum of the values in the 'class' field is equal to 100.

How could I accomplish it directly in the MySQL query without doing it later in PHP?

Thanks everybody!

© Stack Overflow or respective owner

Related posts about mysql