mysql -u {username} -p {databasename} < file_name.sql
1 si groupe 4, sinon 0
SELECT zed_customer.id_customer, CASE WHEN zed_customer_group.id_group = 4 THEN 1 ELSE 0 END AS profil_valide FROM zed_customer LEFT JOIN zed_customer_group ON zed_customer.id_customer = zed_customer_group.id_customer
Sachant qu'il y a des multiples entrées par id_customer mais ne veut que le dernier. On s'aide de GROUP BY pour ça.
SELECT zed_customer.id_customer, MAX(zed_projet_acces.dossier_investissement) AS dossier_investissement, MAX(zed_projet_acces.documents) AS documents FROM zed_customer LEFT JOIN zed_projet_acces ON zed_customer.id_customer = zed_projet_acces.id_customer GROUP BY zed_customer.id_customer
Comment imbriquer des SELECT.
SELECT a.id_customer, a.id_parrain, b.nb_filleuils FROM zed_customer AS a LEFT OUTER JOIN (SELECT id_parrain, COUNT(id_parrain) AS nb_filleuils FROM zed_customer GROUP BY id_parrain) AS b ON a.id_customer = b.id_parrain GROUP BY a.id_customer
DELETE FROM table_name WHERE condition;
On peut utiliser LIKE comme une condition :
SELECT * FROM submission WHERE title LIKE '%gladiator%' // Delete the lines DELETE FROM submission WHERE title LIKE '%gladiator%' OR title LIKE '%tournament%'
// Récupérer le datetime d'il y a 1 heure DATE_ADD( NOW(), INTERVAL -1 HOUR )
Sauce
LIMIT : limite le nombre de résultat total
OFFSET : nombre d'entrée à sauter dans les résultats