Outils pour utilisateurs

Outils du site


informatique:sql

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
informatique:sql [17/08/2009 15:57] – édition externe 127.0.0.1informatique:sql [13/04/2024 14:22] (Version actuelle) – [Manipulons ce qui n'est pas] typo cyrille
Ligne 5: Ligne 5:
 ===== Articles ===== ===== Articles =====
  
-Optimisation MySQL Par Laurent DECORPS \\ +Cours SQL: 
-http://phpinfo.net/articles/article_optimisation-mysql.html#+  * [[http://cerig.pagora.grenoble-inp.fr/tutoriel/bases-de-donnees/sommaire.htm|Les bases de données relationnelles]] par Jean-Claude SOHM avec notamment [[http://cerig.pagora.grenoble-inp.fr/tutoriel/bases-de-donnees/chap20.htm|Chap 20]], [[http://cerig.pagora.grenoble-inp.fr/tutoriel/bases-de-donnees/chap21.htm|Chap 21]] 
 +  * [[https://www.dofactory.com/sql/tutorial|Sql Tutorial]] sur dofactory.com 
 +    * [[https://www.dofactory.com/sql/join|SQL Join]]
  
-Optimisation MySQL 
-http://dev.mysql.com/doc/refman/5.0/fr/mysql-optimization.html\\ 
-Autres conseils d'optimisation\\ 
-http://dev.mysql.com/doc/refman/5.0/fr/tips.html 
  
 ===== Tips ===== ===== Tips =====
 +
 +==== Sql Join ====
 +
 +  * (INNER) JOIN: Select records that have matching values in both tables.
 +  * LEFT (OUTER) JOIN: Select records from the first (left-most) table with matching right table records.
 +  * RIGHT (OUTER) JOIN: Select records from the second (right-most) table with matching left table records.
 +  * FULL (OUTER) JOIN: Selects all records that match either left or right table records.
 +  * All INNER and OUTER keywords are optional
 +
 +Docs:
 +  * [[https://sql.sh/cours/jointures|Jointure SQL]] pas Sql.sh
 +  * [[https://www.dofactory.com/sql/join|{{https://www.dofactory.com/Images/sql-joins.png|SQL Join tutorial}}]] by Dofactory
  
 ==== Données Hiérarchiques (Nested Categories) ==== ==== Données Hiérarchiques (Nested Categories) ====
Ligne 44: Ligne 54:
 ==== Manipulons ce qui n'est pas ==== ==== Manipulons ce qui n'est pas ====
  
-=== Question ===+ou encore: sélection des lignes orphelines. 
 + 
 +**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 62: Ligne 74:
 To find such words, this SELECT query works fine : To find such words, this SELECT query works fine :
  
-   select IID,Word, Feedbacks_IID +<code sql> 
-   from Words LEFT  JOIN Feedbacks_has_Words + select IID,Word, Feedbacks_IID 
-   on IID = Words_IID + from Words 
-   where Feedbacks_IID is null + LEFT JOIN Feedbacks_has_Words 
 + on IID = Words_IID 
 + where Feedbacks_IID is null 
 +</code>
 I could not figure how to right the DELETE Query ... I could not figure how to right the DELETE Query ...
 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 )
  
-==== Insertions ====+**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, dates.measured_at
 +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;
 +</code>
 +
 +==== Insertions ====
  
 **Question** **Question**
Ligne 103: Ligne 133:
  
 REPLACE --> http://dev.mysql.com/doc/refman/5.0/en/replace.html REPLACE --> http://dev.mysql.com/doc/refman/5.0/en/replace.html
 +
 +
 +**pour les accès concurrents avec SELECT FOR UPDATE en SQL**
 +  * https://www.bortzmeyer.org/select-for-update.html
 +  * https://mariadb.com/kb/en/for-update/
 +
 +==== Supprimer doublons ====
 +
 +https://sql.sh/138-methode-supprimer-doublons
 +
 +Compter les doublons:
 +<code sql>
 +SELECT count(*) as DOUBLON, employee_id
 +FROM globalstatements
 +group by employee_id
 +having count(*) > 1
 +limit 100000
 +</code>
 +
 +Les supprimer:
 +<code sql>
 +delete G1 from globalstatements G1
 +LEFT OUTER JOIN (
 +        SELECT MIN(id) as id, employee_id
 +        FROM globalstatements
 +        GROUP BY employee_id
 +    ) as G2
 +    ON G1.id = G2.id
 +WHERE G2.id IS NULL
 +;
 +</code>
 +===== Tools =====
 +
 +==== MySQL Workbench ====
 +
 +[[/informatique/sgbd/mysql#mysql_workbench]]
 +==== HeidiSQL ====
 +
 +https://www.heidisql.com
 +
 +HeidiSQL runs fine on Windows 8 and 10 (and on Windows 7 + 11 with some minor issues).
 +==== Tora ====
 +
 +http://www.torasql.com
 +
 +TOra is an open-source multi-platform database management GUI that supports accessing most of the common database platforms in use, including Oracle, MySQL, and Postgres, as well as limited support for any target that can be accessed through Qt's ODBC support. TOra has been built for various Linux distributions, Mac OS X, MS Windows, and UNIX platforms.
 +
 +In addition to regular query and data browsing functionality, it includes several additional tools useful for database administrators and developers – which aims to help the DBA or developer of database application. Features PL/SQL debugger, SQL worksheet with syntax highlighting, DB browser and a comprehensive set of DBA tools. 
 +
 +==== DB Browser for SQLite ====
 +
 +https://sqlitebrowser.org
 +
 +
 +
 +
  
informatique/sql.1250517422.txt.gz · Dernière modification : 19/05/2012 00:15 (modification externe)

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki