window平台:
(管理员)启动数据库:net start mysql
登陆: mysql -u root -p
create database test;
use test;
项目一:查找重复的电子邮箱
CREATE TABLE email (
ID INT NOT NULL PRIMARY KEY,
Email VARCHAR(255)
)
INSERT INTO email VALUES(‘1‘,‘[email protected]‘);
INSERT INTO email VALUES(‘2‘,‘[email protected]‘);
INSERT INTO email VALUES(‘3‘,‘[email protected]‘);
语句:
select Email from email
group by
having
count(Email) > 1;
项目二:查找大国
-- 创建表
CREATE TABLE World (
name VARCHAR(50) NOT NULL,
continent VARCHAR(50) NOT NULL,
area INT NOT NULL,
population INT NOT NULL,
gdp INT NOT NULL
);
-- 插入数据
INSERT INTO World VALUES( ‘Afghanistan‘, ‘Asia‘,652230,25500100,20343000);
INSERT INTO World VALUES( ‘Albania‘, ‘Europe‘ ,28748,2831741,12960000);
INSERT INTO World VALUES( ‘Algeria‘, ‘Africa‘ ,2381741,37100000,188681000);
INSERT INTO World VALUES( ‘Andorra‘ , ‘Europe‘ ,468,78115,3712000);
INSERT INTO World VALUES( ‘Angola‘ , ‘Africa‘ ,1246700,20609294,100990000);
语句:
select name population area from
World where
population > 25000000 or
area > 3000000 or
gdp > 20000000;