图书--数据库查询
来源:互联网 发布:vscode c环境 编辑:程序博客网 时间:2024/05/29 18:27
use pubs--1.对pubs数据库中的authors表,查询所有作者的信息。select *from authors--2.查询作者所在的城市。select distinct city from authors--3.查询作者编号、姓氏、电话号码及所在城市,查询结果按照作者编号的降序排列。select au_id,au_fname+' '+au_lname 姓名,phone,city from authorsorder by au_id desc--4.查询作者编号、姓氏、电话号码及所在城市,查询结果按照城市降序排列,同一城市的按作者编号的升序排列。select au_id,au_fname+' '+au_lname 姓名,phone,city from authorsorder by city,au_id--5.查询居住在Oakland的作者姓名和电话号码。select au_fname+' '+au_lname 姓名,phone from authorswhere city in ('Oakland')select au_fname+' '+au_lname 姓名,phone from authorswhere city='Oakland'--6.查询居住在Oakland或Berkeley的作者姓名和电话号码。查询结果按照城市升序排列。select au_fname+' '+au_lname 姓名,phonefrom authorswhere city in ('Oakland','Berkeley')order by city--7.查询所有作者全名,结果先按姓氏升序排列,如有雷同,再按照名字排列。select au_fname+' '+au_lname 姓名from authorsorder by au_lname,au_fname--8.pubs数据库,employee表,查询工资水平在100至172之间的员工编号及工资水平。select * from employeeselect emp_id,job_lvl from employeewhere job_lvl between 100 and 172--9.查询authors表中的姓氏,并返回作者名字的首字母--答案select au_lname,substring(au_fname,1,1)--从以一个开始截取第一个from authorsorder by au_lname--函数用法SUBSTR(str,pos): 由<str>中,选出所有从第<pos>位置开始的字元。请注意,这个语法不适用于SQL Server上。 SUBSTR(str,pos,len): 由<str>中的第<pos>位置开始,选出接下去的<len>个字元SELECT SUBSTR(store_name, 3) FROM Geography WHERE store_name = 'Los Angeles'; 结果: 's Angeles' 例2: SELECT SUBSTR(store_name,2,4) FROM Geography WHERE store_name = 'San Diego'; 结果: 'an D' --10.查询authors表中作者姓氏的第2个字母是‘r’的作者信息select *from authorswhere substring(au_lname,2,1)='r'--11.查询authors表中作者姓氏的最后一个字母是‘e’的作者信息.select *from authorswhere au_lname like '%e' select * from authors where right(au_lname,1)='e'--从右数最后一个字母是--12.对上面两题,如果执行查询时不知道表中记录的大小写,该怎么办?select *from authorswhere substring(au_lname,2,1) in ('r','R')select *from authorswhere au_lname like '%e_'andau_lname like '%E_'--13.查询pubs数据库employee中每个雇员的工龄。select * from employee--错误:select fname+' '+lname 姓名,getdate()-hire_date 工龄 from employee--改正select datediff(year,hire_date,getdate())--后面的减去前面的from employee
阅读全文
0 0
- 图书--数据库查询
- 图书查询
- 图书api 查询图书内容
- 豆瓣图书查询升级版“扫扫图书”
- 数据库图书select语句
- 【数据库】图书管理系统
- 图书数据库脚本
- 图书管理数据库
- 基于JAVA的图书数据库管理-具有新增,修改,删除,查询功能
- 图书购买系统之登录注页面--查询数据库进行登录
- Amazon查询图书的方法
- Android豆瓣图书查询Demo
- Android豆瓣图书查询Demo
- jsp查询所有图书信息
- Java图书查询系统实例
- 图书查询时异常处理
- 图书管理系统数据库设计
- 图书管理系统数据库设计
- Unity3d
- 蜂群算法聚类问题的协同过滤推荐
- 数学问题——找“水仙花数”
- 关于移动端使用position:fixed出现抖动情况解决方法
- 设计模式之行为型模式
- 图书--数据库查询
- Maven项目包错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- 浅谈java单例模式
- 动态规划求解最长回文字符串
- 如何中断动画状态机的转换过程?
- 【Linux】Shell总结
- Gulp在前端的常用操作实例
- STM32时钟树分析
- C语言交换两个数字的三种做法