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
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `tablematch`
--------------
--------------
CREATE TABLE `tablematch`
( `id` integer unsigned NOT NULL auto_increment primary key,
`epreuve` varchar(255) NOT NULL,
`date` date NOT NULL,
`lieu` varchar(255) NOT NULL,
`nom` varchar(255) NOT NULL,
`prenom` varchar(255) NOT NULL,
`but` tinyint unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `tablematch` (`epreuve`,`date`,`lieu`,`nom`,`prenom`,`but`) values
('match 1', '2016-06-13', 'lieu 1', 'dupond', 'marc', 1),
('match 2', '2016-06-11', 'lieu 2', 'couet', 'pierre', 3),
('match 3', '2016-06-10', 'lieu 3', 'baud', 'jean', 1),
('match 3', '2016-06-10', 'lieu 3', 'couet', 'pierre', 2),
('match 4', '2016-06-09', 'lieu 4', 'baud', 'jean', 2),
('match 4', '2016-06-09', 'lieu 4', 'couet', 'pierre', 1)
--------------
--------------
select * from tablematch
--------------
+----+---------+------------+--------+--------+--------+-----+
| id | epreuve | date | lieu | nom | prenom | but |
+----+---------+------------+--------+--------+--------+-----+
| 1 | match 1 | 2016-06-13 | lieu 1 | dupond | marc | 1 |
| 2 | match 2 | 2016-06-11 | lieu 2 | couet | pierre | 3 |
| 3 | match 3 | 2016-06-10 | lieu 3 | baud | jean | 1 |
| 4 | match 3 | 2016-06-10 | lieu 3 | couet | pierre | 2 |
| 5 | match 4 | 2016-06-09 | lieu 4 | baud | jean | 2 |
| 6 | match 4 | 2016-06-09 | lieu 4 | couet | pierre | 1 |
+----+---------+------------+--------+--------+--------+-----+
--------------
SELECT epreuve, date, lieu,
max(case when nom = 'couet' and prenom = 'pierre' then but else null end) as 'But Couet Pierre',
max(case when nom = 'baud' and prenom = 'jean' then but else null end) as 'But Baud Jean'
FROM tablematch
WHERE (nom,prenom) in (('couet','pierre'), ('baud','jean'))
GROUP BY epreuve, date, lieu
HAVING COUNT(*) = 2
order by date desc, epreuve
--------------
+---------+------------+--------+------------------+---------------+
| epreuve | date | lieu | But Couet Pierre | But Baud Jean |
+---------+------------+--------+------------------+---------------+
| match 3 | 2016-06-10 | lieu 3 | 2 | 1 |
| match 4 | 2016-06-09 | lieu 4 | 1 | 2 |
+---------+------------+--------+------------------+---------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager