· 7 years ago · Sep 13, 2018, 08:22 AM
1drop table if exists products;
2create table products ( id int, Name char(25) unique,
3 Category char(25), Price integer default 100,
4 Amount integer);
5
6insert into products values (1, 'Book', 'Goods' ,120, 5);
7insert into products values (2, 'Table', 'Goods' , 400, 7);
8insert into products values (3, 'Chair', 'Goods' , 230, 9);
9insert into products values (4, 'Monitor', 'Goods' , 2000, 11);
10insert into products values (5, 'Pen', 'Goods' , 10, 200);
11insert into products (id,Name, Price) values (6, 'Telephone', 5630);
12insert into products (id,Name) values (7, 'Notebook');
13insert into products (id,Name) values (8, 'Charger');
14
15alter table products add column sale int default -5;
16
17select * from products order by Price;
18select * from products order by Price desc;
19select * from products where Name = 'Pen';
20select * from products where Price >= 300;
21select * from products where Price between 150 and 2500;
22select * from products where Amount is null;
23select * from products where Category = 'Goods' and Price >= 100;
24select * from products where Category = 'Goods' or Category is null;
25select * from products where id in (2, 4, 6, 8);
26select * from products where not Name in ('Pen', 'Notebook', 'Charger', 'Table');
27select * from products where Name like '%book%';
28
29drop table if exists newproducts;
30create table newproducts as select id, Name, Price from products;
31select * from newproducts;