Hi,
I have a table named `action` as defined below:
Code:
CREATE TABLE `action` (
`id` TINYINT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` CHAR(12) NOT NULL,
`description` CHAR(250) NOT NULL,
`value` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `value` (`value`),
UNIQUE INDEX `name` (`name`)
)
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=1
I want to find a combination of the action.name fields as CSV whose sum(action.value)=number.
what I'm trying to achieve is not actually a group by since there are no common records to group; I want the combination of name column as CSV from records whose sum(value column) = some number.
for example:
Code:
select CSV(a.name) from action a where sum(a.value)=7;
or perhaps using GROUP_CONCAT like:
Code:
select group_concat(a.name) from `action` a having sum(a.value)=7;
would result in 'view,edit,add'; provided the records with value of view=1, edit=2 and add=4 were present in action table.
I know the above is not a valid SQL query but locgically that statement represents what I'm expecting.
Can you folks guide me in geting above result?
Thanks and Regards,
Samba