查询案列1

create table cetegory(
id int(10) primary key,
name varchar(20)
);
show tables;
select*from cetegory;
insert into cetegory(id,name)values(1,'张三');
desc cetegory;
drop table cetegory;

create table product(
pid int primary key,
pname varchar(20),
price double,
category_id varchar(32)
);
select*from product;
insert into product(pid,pname,price,category_id)values(1,'联想',5000,'c001');
INSERT INTO product(pid,pname,price,category_id) VALUES(2,'海尔',3000,'c001');
INSERT INTO product(pid,pname,price,category_id) VALUES(3,'雷神',5000,'c001');

INSERT INTO product(pid,pname,price,category_id) VALUES(4,'JACK JONES',800,'c002');
INSERT INTO product(pid,pname,price,category_id) VALUES(5,'真维斯',200,'c002');
INSERT INTO product(pid,pname,price,category_id) VALUES(6,'花花公子',440,'c002');
INSERT INTO product(pid,pname,price,category_id) VALUES(7,'劲霸',2000,'c002');

INSERT INTO product(pid,pname,price,category_id) VALUES(8,'香奈儿',800,'c003');
INSERT INTO product(pid,pname,price,category_id) VALUES(9,'相宜本草',200,'c003');
INSERT INTO product(pid,pname,price,category_id) VALUES(10,'面霸',5,'c003');

INSERT INTO product(pid,pname,price,category_id) VALUES(11,'好想你枣',56,'c004');
INSERT INTO product(pid,pname,price,category_id) VALUES(12,'香飘飘奶茶',1,'c005');

INSERT INTO product(pid,pname,price,category_id) VALUES(13,'果9',1,NULL);

select*from product;
-- 查询价格为花花公子的所有信息
select*from product where pname='花花公子';
-- 查询价格为 800的商品
select*from product where price=800;
-- 查询价格不是 800 的商品
select*from product where  price<>800;
-- 查询价格大于60 元的所有商品信息
select*from product where price>60;
-- 查询价格在200或800的商品
select*from product where price between 200 and 1000;
-- 查询价格是 200 或者800的商品
select*from product where price=200 or price=800;
-- 查询含有霸字的所有商品
select*from product where pname like'%霸';
-- 查询以‘香’开头的商品
select*from product where pname like'香%'
-- 查询第二个字为‘想‘的所有商品
select*from product where pname like'_想%';
-- 查询没有分类的商品
select*from product where category_id is null;
-- 查询有分类的商品
select*from product where category_id is not null;

 

posted @ 2018-08-10 16:24  Jskea  阅读(112)  评论(0)    收藏  举报