MySQL中where条件查询(where)

1、查询价格不是800的所有商品(where/!=)

SELECT * FROM product WHERE price != 800

2、查询商品价格在200到1000之间所有商品(between)

SELECT * FROM product WHERE price BETWEEN 200 AND 1000;
SELECT * FROM product WHERE price >= 200 AND price <=1000;

3、查询商品价格是200或800的所有商品(or、in)

SELECT * FROM product WHERE price = 200 OR price = 800;
SELECT * FROM product WHERE price IN (200,800);

4、查询含有’霸’字的所有商品(like)

SELECT * FROM product WHERE pname LIKE '%霸%'
SELECT * FROM product WHERE pname LIKE '_想%'--第二个字为想的
ELECT * FROM product WHERE pname LIKE '香%';--以香开头的

5、查询有分类的商品(null)

SELECT * FROM product WHERE category_id IS NOT NULL
posted @ 2019-07-15 18:40  ah_lydms  阅读(561)  评论(0编辑  收藏  举报