Reputation: 1413
How to get count_id and rating_evarate from table?
I want to count the id and get rating evarate from the table bellow .
how can I do it in mysql .
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `rating`
-- ----------------------------
DROP TABLE IF EXISTS `rating`;
CREATE TABLE `rating` (
`id` int(11) NOT NULL,
`rating` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of rating
-- ----------------------------
INSERT INTO `rating` VALUES ('1', '5');
INSERT INTO `rating` VALUES ('2', '0');
INSERT INTO `rating` VALUES ('3', '0');
INSERT INTO `rating` VALUES ('4', '0');
INSERT INTO `rating` VALUES ('2', '0');
INSERT INTO `rating` VALUES ('1', '0');
Upvotes: 1
Views: 42
Reputation: 32602
You can try this:
SELECT ID
, COUNT(ID) Count_ID
, AVG(Rating) AS rating_average
FROM rating
GROUP BY ID;
Upvotes: 1
Reputation: 4102
you can try this query:
SELECT id, count_id, AVG(rating_average) FROM rating GROUP BY count_id;
Upvotes: 1