select S_Name , S_YuWen, S_ShuXue,(S_YuWen+S_ShuXue)/2.0 as S_AVG
from T
#2
上面写的很对
#3
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
#4
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
这个是模板吗?咋弄出来的?
#5
商业机密...
#6
select *, (S_YuWen+S_ShuXue)/2 as S_AVG from T
#7
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
好奇怪,我自己的环境,不用GROUP BY
#8
额...写错了,上面的代码不需要group by,一开始我用了avg,忘了去除而已
#9
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
还是用除的方便~
select S_Name,S_ShuXue,S_YuWen, (S_ShuXue+S_YuWen)/2 as S_Avg from aa
#13
Microsoft SQL Server 2012
我看到了版本号,也许是版主用了直接生成SQL语句,然后改成自己的名字
#14
Microsoft SQL Server 2012
我看到了版本号,也许是版主用了直接生成SQL语句,然后改成自己的名字
跑题了呵呵。。。楼主威武
#1
select S_Name , S_YuWen, S_ShuXue,(S_YuWen+S_ShuXue)/2.0 as S_AVG
from T
#2
上面写的很对
#3
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
#4
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
这个是模板吗?咋弄出来的?
#5
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
这个是模板吗?咋弄出来的?
商业机密...
#6
select *, (S_YuWen+S_ShuXue)/2 as S_AVG from T
#7
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
好奇怪,我自己的环境,不用GROUP BY
#8
额...写错了,上面的代码不需要group by,一开始我用了avg,忘了去除而已
#9
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[T]
if object_id('[T]') is not null drop table [T]
go
create table [T]([S_Name] varchar(4),[S_YuWen] int,[S_ShuXue] int)
insert [T]
select '张三',80,80 union ALL
select '李五',0,100
--------------开始查询--------------------------
select *,([S_YuWen]+[S_ShuXue])/2
from [T]
GROUP BY [S_Name],[S_YuWen],[S_ShuXue]
----------------结果----------------------------
/*
S_Name S_YuWen S_ShuXue
------ ----------- ----------- -----------
李五 0 100 50
张三 80 80 80
*/
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-02-13 11:38:06
-- 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: )
--
----------------------------------------------------------------