1.创建一个表products
CREATE TABLE products
( product_id integer,
product_name char(30),
category char(30)
) ;
2.向表中插入数据,采用一次插入一条和多条记录的方式
INSERT INTO products (product_id, product_name, category) VALUES (1502, 'olympus camera', 'electrncs');
INSERT INTO products (product_id, product_name, category) VALUES
(1502, 'olympus camera', 'electrncs'),
(1601, 'lamaze','toys'),
(1700, 'wait interface', 'Books'),
(1666, 'harry potter', 'toys');
3.查询表中所有记录及记录数
\dt products
select * from products;
select count(*) from products;
4.查询表中所有category记录,并将查询结果按升序排序
select category from products;
select category from products order by category;
select category, product_name from products order by category desc, product_name asc;
5.查询表中category为toys的记录
select * from products where category='toys';
6.删除表products
drop products;