Skip to content

Instantly share code, notes, and snippets.

@eduardogpg
Created December 3, 2022 01:12
Show Gist options
  • Select an option

  • Save eduardogpg/78e0268e10ce17e9c68fe54a1f1c9146 to your computer and use it in GitHub Desktop.

Select an option

Save eduardogpg/78e0268e10ce17e9c68fe54a1f1c9146 to your computer and use it in GitHub Desktop.
CREATE DATABASE IF NOT EXISTS bootcamp;
USE bootcamp;
DROP TABLE IF EXISTS users;
CREATE TABLE users(
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, -- Este es un campo único.
name VARCHAR(50) NOT NULL,
age INT NOT NULL,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(50) NOT NULL,
country VARCHAR(20) NOT NULL,
cp VARCHAR(20) NOT NULL,
gender ENUM('male', 'female') NOT NULL DEFAULT 'female',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- SELECT name, email FROM users;
-- SELECT name FROM users WHERE gender = 'female';
-- SELECT name FROM users WHERE gender = 'male' AND age > 49;
-- SELECT * FROM users WHERE age > 20;
-- SELECT username FROM users WHERE age > 30 AND age < 50;
-- SELECT usernamem, emai FROM users WHERE email LIKE '%@example.com';
-- SELECT username FROM users WHERE country = 'Germany' OR country = 'Finland' OR country = 'Canada';
-- SELECT username FROM users WHERE country IN ('Germany', 'Canada', 'Finland'
-- SELECT username FROM users WHERE id IN (SELECT id FROM users WHERE country IN ('Germany', 'Canada', 'Finland'));
-- SELECT COUNT(*) FROM (SELECT DISTINCT country FROM users) AS result;
-- SELECT name, email FROM users WHERE gender = 'female' AND country = 'Germany';
-- SELECT AVG(age) FROM users WHERE gender = 'female' AND age > 20 AND country = 'Canada';
-- SELECT COUNT(*) FROM users WHERE country = 'Finland';
-- Select count(*), gender from users group by gender;
-- SELECT country, count(*) as total FROM users WHERE gender = 'female' GROUP By country ORDER BY total DESC LIMIT 1;
-- SELECT country, COUNT(*) as total FROM users GROUP BY country ORDER BY total DESC LIMIT 3;
-- SELECT country, age, name FROM users ORDER BY age DESC LIMIT 1;
-- SELECT country, AVG(age) AS avg FROM users GROUP BY country ORDER BY avg DESC LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment