informatique:sql
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
informatique:sql [16/02/2021 11:54] – [Supprimer doublons] cyrille | informatique:sql [23/01/2025 17:34] (Version actuelle) – [Sql Join] update avec join cyrille | ||
---|---|---|---|
Ligne 24: | Ligne 24: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | |||
+ | Et pour un '' | ||
+ | |||
+ | <code sql> | ||
+ | UPDATE `table_a` a | ||
+ | LEFT JOIN `table_b` b ON a.id = b.id | ||
+ | SET a.password = ' | ||
+ | WHERE b.id = 195812 | ||
+ | </ | ||
==== Données Hiérarchiques (Nested Categories) ==== | ==== Données Hiérarchiques (Nested Categories) ==== | ||
Ligne 56: | Ligne 65: | ||
ou encore: sélection des lignes orphelines. | ou encore: sélection des lignes orphelines. | ||
- | === Question | + | **Question** |
I've got a SELECT query that I would like to transform as a DELETE query , | I've got a SELECT query that I would like to transform as a DELETE query , | ||
Ligne 84: | Ligne 93: | ||
Have you got a idea about it ??? | Have you got a idea about it ??? | ||
- | === Answer | + | **Answer** |
DELETE FROM Words WHERE IID NOT IN | DELETE FROM Words WHERE IID NOT IN | ||
( SELECT Words_ID FROM Feedbacks_has_Words ) | ( SELECT Words_ID FROM Feedbacks_has_Words ) | ||
+ | |||
+ | **Question** | ||
+ | |||
+ | Avec une base de données sqlite avec 2 tables. Une table contient les stations métérologiques et une table contient les mesures de températures journalières pour ces stations. Comment trouver en SQL les dates et les stations pour lesquelles il manque des mesures ? | ||
+ | |||
+ | **Réponse** | ||
+ | |||
+ | <code sql> | ||
+ | SELECT s.id, s.name AS nom_station, | ||
+ | FROM stations s | ||
+ | CROSS JOIN ( | ||
+ | SELECT DISTINCT measured_at FROM measures | ||
+ | ) AS dates | ||
+ | LEFT JOIN measures m ON s.id = m.station_id AND dates.measured_at = m.measured_at | ||
+ | WHERE m.station_id IS NULL | ||
+ | ORDER BY s.id, dates.measured_at; | ||
+ | </ | ||
==== Insertions ==== | ==== Insertions ==== | ||
Ligne 116: | Ligne 142: | ||
REPLACE --> http:// | REPLACE --> http:// | ||
+ | |||
+ | |||
+ | **pour les accès concurrents avec SELECT FOR UPDATE en SQL** | ||
+ | * https:// | ||
+ | * https:// | ||
==== Supprimer doublons ==== | ==== Supprimer doublons ==== | ||
Ligne 121: | Ligne 152: | ||
https:// | https:// | ||
+ | Compter les doublons: | ||
+ | <code sql> | ||
+ | SELECT count(*) as DOUBLON, employee_id | ||
+ | FROM globalstatements | ||
+ | group by employee_id | ||
+ | having count(*) > 1 | ||
+ | limit 100000 | ||
+ | </ | ||
+ | |||
+ | Les supprimer: | ||
<code sql> | <code sql> | ||
delete G1 from globalstatements G1 | delete G1 from globalstatements G1 | ||
Ligne 132: | Ligne 173: | ||
; | ; | ||
</ | </ | ||
+ | |||
+ | ==== Supprimer dans plusieurs tables ==== | ||
+ | |||
+ | Supprimer les lignes dans les tables wp2r_posts et wp2r_postmeta : | ||
+ | |||
+ | <code sql> | ||
+ | DELETE m , p | ||
+ | FROM wp2r_posts p INNER JOIN wp2r_postmeta m | ||
+ | WHERE m.post_id= p.ID | ||
+ | and p.post_type=" | ||
+ | </ | ||
+ | |||
+ | |||
===== Tools ===== | ===== Tools ===== | ||
==== MySQL Workbench ==== | ==== MySQL Workbench ==== | ||
+ | [[/ | ||
==== HeidiSQL ==== | ==== HeidiSQL ==== | ||
+ | https:// | ||
+ | |||
+ | HeidiSQL runs fine on Windows 8 and 10 (and on Windows 7 + 11 with some minor issues). | ||
==== Tora ==== | ==== Tora ==== | ||
Ligne 145: | Ligne 203: | ||
In addition to regular query and data browsing functionality, | In addition to regular query and data browsing functionality, | ||
+ | |||
+ | ==== DB Browser for SQLite ==== | ||
+ | |||
+ | https:// | ||
+ | |||
informatique/sql.1613472894.txt.gz · Dernière modification : 16/02/2021 11:54 de cyrille