Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to get vistors_sum and reviews_count in 3 table?
    primarykey
    data
    text
    <p>how to get vistors_sum and reviews_count in 3 table ? see the bellow codes, how to get my result in one sql?</p> <pre><code>SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `a` -- ---------------------------- DROP TABLE IF EXISTS `a`; CREATE TABLE `a` ( `products_id` int(11) NOT NULL, `products_name` varchar(255) default NULL, PRIMARY KEY (`products_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of a -- ---------------------------- INSERT INTO `a` VALUES ('1', 'jimmy'); INSERT INTO `a` VALUES ('2', 'tina'); INSERT INTO `a` VALUES ('3', 'emma'); SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `b` -- ---------------------------- DROP TABLE IF EXISTS `b`; CREATE TABLE `b` ( `id` int(11) NOT NULL auto_increment, `products_id` int(11) NOT NULL, `vistors` int(11) NOT NULL, `date` date default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of b -- ---------------------------- INSERT INTO `b` VALUES ('1', '1', '1', '2013-11-13'); INSERT INTO `b` VALUES ('2', '1', '2', '2013-11-04'); INSERT INTO `b` VALUES ('3', '2', '1', '2013-11-13'); INSERT INTO `b` VALUES ('4', '2', '3', '2013-11-13'); SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for `c` -- ---------------------------- DROP TABLE IF EXISTS `c`; CREATE TABLE `c` ( `id` int(11) NOT NULL auto_increment, `products_id` int(11) NOT NULL, `review_content` varchar(255) default NULL, `date` date default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of c -- ---------------------------- INSERT INTO `c` VALUES ('1', '1', 'hello', '2013-11-13'); INSERT INTO `c` VALUES ('2', '1', 'world', '2013-11-13'); INSERT INTO `c` VALUES ('3', '2', 'good', '2013-11-12'); INSERT INTO `c` VALUES ('4', '3', 'boy', '2013-11-13'); </code></pre> <p><img src="https://i.stack.imgur.com/apxRn.png" alt="enter image description here"></p> <p>this code bellow can do but the date condition is in sub children temp table. this make the sql not flexible (if I want to query any time not 2013-11-13)</p> <pre><code>select a.products_id, a.products_name, b.vistors_sum, c.reviews_count from a left join ( select b.products_id, b.date, sum(b.vistors) as vistors_sum from b where b.date = '2013-11-13' group by b.products_id ) as b on a.products_id = b.products_id left join ( select c.products_id, count(c.products_id) as reviews_count from c where c.date = '2013-11-13' group by c.products_id ) as c on a.products_id = c.products_id </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload