Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SQL code to introduce lesson 1 - Work with a table
CREATE TABLE clients (
id INT primary key,
nom VARCHAR(255),
prenom VARCHAR(255),
ZIP INT
);
INSERT INTO clients (id, nom, prenom, ZIP) VALUES (1,"TOTO", "André", 63000);
INSERT INTO clients (id, nom, prenom, ZIP) VALUES (2,"TATA", "André", 99000);
INSERT INTO clients (id, nom, prenom, ZIP) VALUES (3,"fgdfgdf", "Henri", 98000);
INSERT INTO clients (id, nom, prenom, ZIP) VALUES (4,"fgdfgdf", "Henri", 75000);
INSERT INTO clients (id, nom, prenom, ZIP) VALUES (5,"fgdfgdf", "Xavier", 01000);
-- SELECT count(*) AS "Nombre d'invités pour ce soir" FROM clients;
-- Calculs
-- SELECT 1 + 1 ;
-- Sélection de colonnes
-- SELECT nom, prenom FROM clients;
-- restriction de lignes
-- SELECT * FROM clients WHERE id = 1;
-- Opérateur distinct, suppression des doublons
-- SELECT DISTINCT(prenom) FROM clients;
-- Expression complexe de restriction
-- SELECT * FROM clients WHERE ZIP < 75000 AND nom LIKE "f%";
-- Nombre de clients de ZIP = 75000
-- SELECT COUNT(*) AS "Nombre de client du ZIP = 75000" FROM clients WHERE ZIP = 75000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment