显示没有重复记录的商品名称,商品价格和商品类别列表
select distinct ware_name,price from t_ware;
查询所有商品价格提高20%后的价格
select ware_id,ware_name,price*1.2 from t_ware'
a) 不使用as
select ware_id,ware_name,price*1.2 price_raise from t_ware;
b)使用as
select ware_id,ware_name,price*1.2 price_raise from t_ware;
select ware_id,ware_name,price,category_id from t_ware where not price>100;
select ware_id,ware_name,price,category_id from t_ware where category_id or category_id=6 or category_id=7;
select ware_id,ware_name,price,category_id from t_ware where not price>100 and category_id = 5;
显示商品价格在200元至1000元之间的商品(留心一下,是半开区间还是封闭区间?)
select ware_id,ware_name,price,category_id from t_ware where price between 200 and 1000;
显示商品类别为5,6,7且价格不小于200元的商品
select ware_id,ware_name,price,category_id from t_ware where category_id in (5,6,7) and price>=200;
select ware_id,ware_name,price,category_id from t_ware where ware_name like '%纯棉%';
select ware_id,ware_name,price,category_id from t_ware where ware_name like '%长袖_恤%';
select ware_id,ware_name,price,category_id from t_ware where ware_name like '%\%%' escape '\';
select * from t_ware_category where parent_id = 0 order by ware_id ;
select * from t_ware_category where parent_id = 0 order by ware_id asc;
select * from t_ware_category where parent_id = 0 order by ware_id desc ;
select ware_id,ware_name,price from t_ware where rownum <= 20;
select ware_id,ware_name,price from t_ware where rownum<=10 and ware_id not in(select ware_id from t_ware where rownum<=10);
查询商品编号,商品名称,商品价格和商品类别名称
select t_ware.ware_id, t_ware.ware_name, t_ware.price ,t_ware_category_name from t_ware, t_ware_category where t_ware.category_id=t_ware_category.category_id;
select t_ware.ware_id,t_ware.ware_name,t_ware.price,t_ware_category.category_name from t_ware left join t_ware_category on t_ware.category_id=t_ware_category.category_id;
select w.ware_id,w.ware_name,w.price,wc.category_name from t_ware w left join t_ware_category wc on w.category_id=wc.category_id;
select t_ware.ware_id,t_ware.ware_name,t_ware.price,t_ware_category.category_name from t_ware left join t_ware_category on t_ware.category_id=t_ware_category.category_id;
select ware_id,ware_name from t_ware where ware_name like '%T恤%' union select ware_id,ware_name from t_ware where ware_name like '%手提包%'
select w.category_id,wc.category_name,count(w.ware_id),sum(w.price) from t_ware w left join t_ware_category wc on w.category_id=wc.category_id group by w.category_id,wc.category_name;
select wc2.category_id,wc2.category_name,sum(w.price) from t_ware w left join t_ware_category wc on w.category_id=wc.category_id left join t_ware_category wc2 on wc.parent_id=wc2.category_id group by wc2.category_id,wc2.category_name;
–举例子说明:查询table表查询每一个班级中年龄大于20,性别为男的人数
select COUNT(*)as '>20岁人数',classid from Table1 where sex='男' group by classid,age having age>20