Using the table code below I was asked to draw out a list sorted by the rankings of each item. Each column rank# is how each user would rank that item. So for an item A if it was ranked 1 by one user and 16 by another its overall ranking should be 8. Is there a possible SQL query for this or process it in PHP?
CREATE TABLE `rankings` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`userId` int(11) NOT NULL,
`rank1` int(11) NOT NULL,
`rank2` int(11) NOT NULL,
`rank3` int(11) NOT NULL,
`rank4` int(11) NOT NULL,
`rank5` int(11) NOT NULL,
`rank6` int(11) NOT NULL,
`rank7` int(11) NOT NULL,
`rank8` int(11) NOT NULL,
`rank9` int(11) NOT NULL,
`rank10` int(11) NOT NULL,
`rank11` int(11) NOT NULL,
`rank12` int(11) NOT NULL,
`rank13` int(11) NOT NULL,
`rank14` int(11) NOT NULL,
`rank15` int(11) NOT NULL,
`rank16` int(11) NOT NULL,
`submissionTimestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
Here is the table that each rank# column is referenced to:
CREATE TABLE `rankableItems` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`itemName` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
I think you take it the wrong way. Here what you could do that will be much more simple to work with and to understand :
And the associated query to get the average ranking :