1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `base`
DEFAULT CHARACTER SET `utf8`
DEFAULT COLLATE `utf8_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `product_productextras`
--------------
--------------
CREATE TABLE `product_productextras`
( `id_pei` integer UNSIGNED NOT NULL AUTO_INCREMENT,
`id_product` integer UNSIGNED NOT NULL,
PRIMARY KEY (`id_pei`)
) ENGINE=InnoDB
DEFAULT CHARSET=`utf8` COLLATE=`utf8_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `product_productextras` (`id_pei`,`id_product`) values
(1, 25), (2, 12), (3, 44), (4, 75), (5, 32), (6, 24)
--------------
--------------
select * from product_productextras
--------------
+--------+------------+
| id_pei | id_product |
+--------+------------+
| 1 | 25 |
| 2 | 12 |
| 3 | 44 |
| 4 | 75 |
| 5 | 32 |
| 6 | 24 |
+--------+------------+
--------------
DROP TABLE IF EXISTS `product_productextras_lang`
--------------
--------------
CREATE TABLE `product_productextras_lang`
( `id_pei` integer unsigned NOT NULL AUTO_INCREMENT,
`id_lang` integer unsigned NOT NULL,
`notice` text DEFAULT NULL,
`about` text DEFAULT NULL,
PRIMARY KEY (`id_pei`, `id_lang`),
CONSTRAINT `fk_productextras_id_pei` FOREIGN KEY (`id_pei`) REFERENCES `product_productextras` (`id_pei`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB
DEFAULT CHARSET=`utf8` COLLATE=`utf8_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
insert into `product_productextras_lang` (`id_pei`,`id_lang`,`notice`,`about`) values
(1, 1, 'x', 'x'),
(1, 2, 'x', 'x'),
(1, 3, 'x', 'x'),
(2, 1, 'x', 'x'),
(2, 2, 'x', 'x'),
(2, 3, 'x', 'x'),
(3, 1, 'x', 'x'),
(3, 2, 'x', 'x'),
(3, 4, 'x', 'x'),
(4, 1, 'x', 'x'),
(4, 2, 'x', 'x'),
(5, 1, '', ''),
(5, 2, '', ''),
(5, 3, '', ''),
(6, 1, 'x', 'x'),
(6, 2, '', ''),
(6, 3, 'x', 'x')
--------------
--------------
select * from product_productextras_lang
--------------
+--------+---------+--------+-------+
| id_pei | id_lang | notice | about |
+--------+---------+--------+-------+
| 1 | 1 | x | x |
| 1 | 2 | x | x |
| 1 | 3 | x | x |
| 2 | 1 | x | x |
| 2 | 2 | x | x |
| 2 | 3 | x | x |
| 3 | 1 | x | x |
| 3 | 2 | x | x |
| 3 | 4 | x | x |
| 4 | 1 | x | x |
| 4 | 2 | x | x |
| 5 | 1 | | |
| 5 | 2 | | |
| 5 | 3 | | |
| 6 | 1 | x | x |
| 6 | 2 | | |
| 6 | 3 | x | x |
+--------+---------+--------+-------+
--------------
select t1.id_pei,
t1.id_product
from product_productextras as t1
inner join product_productextras_lang as t2
on t2.id_pei = t1.id_pei
and t2.notice <> ''
and t2.about <> ''
group by t1.id_pei, t1.id_product
having count(distinct t2.id_lang) = 3
order by t1.id_pei, t1.id_product
--------------
+--------+------------+
| id_pei | id_product |
+--------+------------+
| 1 | 25 |
| 2 | 12 |
| 3 | 44 |
+--------+------------+
--------------
explain
select t1.id_pei,
t1.id_product
from product_productextras as t1
inner join product_productextras_lang as t2
on t2.id_pei = t1.id_pei
and t2.notice <> ''
and t2.about <> ''
group by t1.id_pei, t1.id_product
having count(distinct t2.id_lang) = 3
order by t1.id_pei, t1.id_product
--------------
+----+-------------+-------+------------+------+---------------+---------+---------+----------------+------+----------+----------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+---------+---------+----------------+------+----------+----------------+
| 1 | SIMPLE | t1 | NULL | ALL | PRIMARY | NULL | NULL | NULL | 6 | 100.00 | Using filesort |
| 1 | SIMPLE | t2 | NULL | ref | PRIMARY | PRIMARY | 4 | base.t1.id_pei | 1 | 81.00 | Using where |
+----+-------------+-------+------------+------+---------------+---------+---------+----------------+------+----------+----------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager