有多少个表就要关联多少次,没得省了.如果表都没有关联,哪来的数据呢
解决方案 »
- 存储过程,变量释放
- 什么是 查询成本 ? 如何查看某个sql 语句的执行时间 ? 表建立了索引 如何得知sql server 是否使用了该索引?
- 在select里,“[]”表示什么?
- 如何从数据库中读取image字段
- 关于触发器,可能比较难,有高手能帮忙解决一下吗?
- 这条SQL语句怎么写,各位帮帮忙:知道某字段下的值,看看这个字段下的值还存在当前数据库的哪些表里,这个语句怎么写???
- SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的问题
- 如何把vfp中的表SQL的數据庫中表
- 急求一SQL,请高手进来
- 能否实现SQL附加数据库和增加登录用户自动化。
- sqlserver 断电后 表全部丢失是什么原因??如何恢复???
- create database成功执行,却没看到创建的数据库
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-27 08:12:33
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[a]
if object_id('[a]') is not null drop table [a]
go
create table [a]([sno] int,[sco] int)
insert [a]
select 1,20 union all
select 2,30 union all
select 3,35 union all
select 4,49
--> 测试数据:[b]
if object_id('[b]') is not null drop table [b]
go
create table [b]([sno] int,[sco] int)
insert [b]
select 1,11 union all
select 2,22 union all
select 3,33 union all
select 4,31
--> 测试数据:[c]
if object_id('[c]') is not null drop table [c]
go
create table [c]([sno] int,[sco] int)
insert [c]
select 1,120 union all
select 2,130 union all
select 3,135 union all
select 4,149
--------------开始查询--------------------------SELECT a.sno,a.sco AS '语文' ,b.sco AS '英语',c.sco AS '文综',a.sco+b.sco+c.sco '总成绩'
FROM a JOIN b ON a.sno=b.sno
JOIN c ON a.sno=c.sno
----------------结果----------------------------
/*
sno 语文 英语 文综 总成绩
----------- ----------- ----------- ----------- -----------
1 20 11 120 151
2 30 22 130 182
3 35 33 135 203
4 49 31 149 229
*/