declare @t table(n int)
declare @i int=1
while(@i<1000)
begininsert into @t select @iset @i=@i+1
end
--select * from @t--1. copy all employees five times.
--select e.empid,e.firstname,e.lastname, t.n from hr.Employees e, @t t where t.n<6--2. 为每个雇员和从09年6月12日至09年6月16日范围内的每天返回一行.
--select e.empid,e.firstname,e.lastname,DATEADD(day, t.n,'2009-06-12') from hr.Employees e, @t t
--where t.n<6 order by empid--3. 返回来自美国的客户, 并为每个客户返回其订单总数和商品交易总数量
--select c.custid, count(o.orderid), sum(od.qty) from
--Sales.Customers c , Sales.Orders o, Sales.OrderDetails od
--where c.country='usa' and c.custid=o.custid and o.orderid=od.orderid group by c.custid--4. 返回客户及其订单信息,  包括没有下过任何订单的客户.
--select c.custid,c.companyname, o.orderid, o.orderdate
--from Sales.Customers c left join Sales.Orders o on c.custid=o.custid--4. 返回没有下过订单的客户
--select c.custid,c.companyname, o.orderid, o.orderdate
--from Sales.Orders o right join  Sales.Customers c on c.custid=o.custid where o.orderid is null--5. 返回在07年2月12日下过订单的客户, 以及他们的订单
--select c.custid,c.companyname, o.orderid, o.orderdate
--from Sales.Orders o right join  Sales.Customers c on c.custid=o.custid
--where o.orderdate='2007-02-12'--6. 返回在2007年2月12日下过订单的客户, 以及他们的订单. 也返回在2007年2月12日没有下过订单的客户
select c.custid,c.companyname,
case when o.orderid IS null then 'no' else  'yes' end
from Sales.Orders o right join  Sales.Customers c on
(c.custid=o.custid and o.orderdate='2007-02-12')

转载于:https://www.cnblogs.com/jianjialin/archive/2012/04/09/2438626.html

sql server 2008语言基础: 连接查询习题相关推荐

  1. sql server 2008语言基础: 集合

    --declare @t table(n int) --insert into @t values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9) --select * ...

  2. 彻底解决SQL SERVER 2008无法远程连接的问题

    1.想要彻底解决SQL SERVER 2008无法远程连接的问题必须按照步骤来 一.为 SQL 启用远程连接 1. 单击"开始",依次指向"程序"." ...

  3. SQL Server 2008从基础开始学习的历程(1)------创建表与查询

    [by:yy] 无论我们学什么呢,都要讲究一个Why,一个How.那么我们为什么要学SQL呢?无非就那么几点. 1.为了适应其他技术,和其他技术配对而学. 我个人的理解呢,只要在IT行业,无论你学什么 ...

  4. Microsoft SQL Server 2008技术内幕:T-SQL查询---------查询优化

    示例数据库: -- Sample Data for this Chapter -- Listing 4-1: Creation Script for Sample Database and Table ...

  5. Microsoft SQL Server 2008技术内幕:T-SQL查询---------逻辑查询处理

    Three-Valued Logic(三值逻辑) SQL values: TRUE, FALSE, UNKNOWN 由于查询筛选器中 (ON, WHERE, and HAVING) 将UNKNOW认定 ...

  6. pb6连接本地sqlserver连不上连远程服务器可以连上,sql server 2008和PB9连接不上 怎么处理呀...

    1.SQL sp4 2.可以试着用ODBC测试看能不能连接上SQL,如果能连上,证明数据库没问题. 3.如果是脱离PB环境,检查你的DLL文件是否齐全. 4.如果不用SQLCA,代码如下: If No ...

  7. SQL Server 2008 开启远程连接

    除了 IP1.IP2 外,也要把 IPALL 的端口也设置为 1433 参考:SQL Server开启1433端口,彻底解决方案 转载于:https://www.cnblogs.com/victorb ...

  8. SQL Server【三】连接查询

    将两个表或者两个以上的表以一定的连接条件连接起来,从中检索出满足条件的数据. 内连接 使用inner join,inner可以省略 -- 查询员工的姓名和部门名称 select "E&quo ...

  9. SQL Server数据库作业:连接查询

    目录 一.等值与非等值连接查询 1.等值连接 2.自然连接 二.自身连接 三.外连接 四.多表连接 一.等值与非等值连接查询 1.等值连接 条件Student.Sno=SC.Sno把Student表的 ...

  10. sql server 2008 64位连接sql 2000服务器出错解决办法

    http://support.microsoft.com/kb/906954/zh-tw 报错: 链接服务器"seeker2k4"的 OLE DB 访问接口 "SQLNC ...

最新文章

  1. c 各种编译器(gcc clang)
  2. EntityFramework 7.0之初探【基于VS 2015】(十)
  3. 使用DocFX生成文档
  4. SpringBoot高级-检索-SpringBoot整合Jest操作ES
  5. BeautifulSoup4 find_all搜索包含指定文本内容的标签返回空list的问题
  6. Java经典设计模式(1):五大创建型模式(附实例和详解)
  7. libuv 与 libev 的对比
  8. 小数保留4位_实验结果保留几位有效数字?
  9. 第3章 如何赢得客户
  10. 软件测试常问面试题,你真的会搭建测试环境吗?
  11. 5分钟快速了解区块链中的哈希值Hash(用户密码存储举例说明)?
  12. linux服务器挂载ntfs u盘,如何在linux下挂载NTFS格式的U盘或硬盘。
  13. 检查Telerik UI以使用UWP作为PVS-Studio的入门方法
  14. ESP32 天气预报 彩屏
  15. ios:新浪微博iphone客户端
  16. Home Assistant 发现小米设备
  17. 【论文阅读|深读】GAS:Role-Oriented Graph Auto-encoder Guided by Structural Information
  18. 2021年奥利给好看高考倒计时源码
  19. anaconda安装软件包
  20. Kafka工具--滴滴Logi-KafkaManager

热门文章

  1. CAS单点登陆,URL多出个参数jsessionid导致登陆失败问题
  2. wine linux 目录,wine的安装与microsoft office在linux上的运行
  3. stc和sac_短期成本曲线
  4. StringBoot接收XML参数,Java解析XML参数并封装
  5. 设计模式之——桥接模式
  6. ERROR: The minSdk version should not be declared in the android manifest file.
  7. Prototype使用$R()函数
  8. 23种设计模式(九)对象创建之原型模式
  9. (备忘)Java web项目迁移到Centos7中验证码无法显示
  10. 表级约束和列级约束(二十)