50分 解决一个SQL查询问题 - MS-SQL Server / 基础类
SQL code:
有一个表A 里面有三个字段
a int
b int
c int
表里的数据为
a b c
________
3 9 5
5 2 7
6 3 8
用最简单的方法查出表里最大的数据
只要查询结果为 9 即刻给分.................
SQL code:
select
max(a)
from
(select a from tb
union all
select b as a from tb
union all
select c as a from tb
)t
SQL code:
----------------------------------------------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2010-05-06 16:45:10
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([a] int,[b] int,[c] int)
insert [tb]
select 3,9,5 union all
select 5,2,7 union all
select 6,3,8
--------------开始查询--------------------------
select
max(a)
from
(select a from tb
union all
select b a
相关问答:
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......
sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
有2个数据表A与B,如何补充A中没有,B中有的数据,使A表数据完整?请写下具体源代码
SQL code:
insert A select * from A right join B on A.key=b.key where A.key is null
select * from B left join ......