您的位置:首页 > 运维架构 > Linux

Slackware中文帮助文档(第一章 Slackware Linux简介)

2009-06-04 22:58 661 查看
表中数据的查询
制作人:丁琪 QQ:854804038
一、在market数据库中:
说明:
market数据库三张表(customers,goods,orders)
goods商品表(name商品名,storage库存量,supplier供应商,status商品状态,price商品价格)
orders订单表(orderid订单编号,goodsname商品名,customerid客户编号,quantity订货数量,ordersum订货金额,orderdate订货日期)
1、从goods表中查询所有商品信息:select * from goods



2、从customers表中查询客户的姓名和电话:select lastname as '用户姓名',tel as '用户电话' from customers



3、查询customers表,显示客户编号和客户姓名,使customerid列显示的列名为“客户编号”,将lastname和firstname列组合起来成为结果集中的“姓名”列:select customerid as '客户编号',(lastname+','+firstname)as '姓名' from customers



4、查看哪些货品有订单。(查询订单表中商品名,去掉重复商品名):select distinct goodsname as '商品名' from orders



5、查看订货金额最大的前三笔订单:select top 3 ordersum as '订货金额' from orders order by ordersum desc



6、查看货品“tv”的货存量情况:select name,storage from goods where name='tv'



7、查看库存量大于4的货品:select name as '货品名称',storage as '库存量' from goods where storage>4



8、查询发生在2007/4/17日到2007/4/18日之间的订单:select orderid,goodsname,customerid,quantity,ordersum,orderdate from orders
where orderdate>='2007-4-17'and orderdate<='2007-4-19'



9、查询北京、上海、天津三地的客户:select firstname,lastname,city from customers where city='北京'or city='上海'or city='天津'



10、查询电话号码第一位不是8的客户:select firstname,lastname,tel from customers where tel not like '8%'



11、查询所有customers表中没有登记电话号码的客户:select * from customers where tel is null



12、查询货品为"tv"且订货金额大于5000的订单:select * from orders where goodsname='tv' and ordersum>5000



13、查找goods表中最贵的定价:select max(ordersum)as '最贵的定价'from orders



14、查询客户的个数:select count(customerid) as '客户的个数' from customers



15、查询订单表中每一种货品的订货总数:select goodsname as '商品名',sum(quantity) as '订货数量' from orders group by goodsname



16、查询订货总数大于500的货品:select sum(quantity) as '订货数量',goodsname as '商品名' from orders group by goodsname
having sum(quantity)>500



17、查询在2007/4/18日之后的订单的金额:select ordersum as '订货金额',orderdate as '订货日期' from orders where orderdate>'2007-4-18'



18、查询在2007/4/18日之后的订单的金额,并统计每种货品的订单总金额啊:select orderid,goodsname,customerid,quantity,ordersum,orderdate from orders
where orderdate>'2007-04-18' order by goodsname compute sum(ordersum) by goodsname


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: