SQL DEMO
CREATE DATABASE qldulich;
USE qldulich;
CREATE TABLE mytable
(
id INT not null PRIMARY KEY,
name VARCHAR(20) not null,
gioitinh nchar(7),
birtday datetime not null,
place varchar(255) not null,
diachi varchar(255)not null,
)
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 1,'Will1',1,'1956','hcm','hcm1' );
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 2,'Will2',1,'1956','hcm','hcm1' );
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 3,'Will3',1,'1956','hcm','hcm1' );
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 4,'Will4',1,'1920','hcm','hcm1' );
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 5,'Will5',1,'1959','hcm','hcm1' );
INSERT INTO mytable (id,name,gioitinh,birtday,place,diachi) VALUES ( 6,'Will6',1,'1957','hcm','hcm1' );
--
select * from mytable
--hien thi ten va gioi tinh
select name,gioitinh from mytable
select name,place from mytable
select distinct place from mytable
--update lai database
update mytable set name = 'Nguyen Van A'where id = 1
update mytable set name = 'Nguyen Van B'where id = 2
update mytable set name = 'Nguyen Van C'where id = 3
update mytable set name = 'Nguyen Van D'where id = 4
update mytable set name = 'Nguyen Van E'where id = 5
update mytable set name = 'Nguyen Van F'where id = 6
--- Kiem tra Lai Thu
select * from mytable
--hien thi ho ten va nam sinh theo kieu tang dan
select name,birtday from mytable order by birtday asc
--hien thi ho ten va nam sinh theo kieu giam dan
select name,birtday from mytable order by birtday desc
--- where
select name,birtday from mytable where id=1 or id=2
--- where hien thi dieu kien va nam sinh lon hon 1950
select * from mytable
select name,birtday from mytable where name = 'Will' OR name = 'Will2';
select name,birtday from mytable Where (name = 'Will' OR name = 'Will2') and (birtday > '1950');
select * from mytable
select name,birtday from mytable where birtday+20 > year
--hien thi theo nam sinh = 1956
C1
select * from mytable where birtday = '1956';
C2
-- in tap hop
select * from mytable where birtday IN ('1950','1956');
-- them not gia tri ko thuoc tap hop
select * from mytable where birtday NOT IN ('1950','1956');
-- Lam Viec Vs Between

COMMENTS