sql 连接问题! - MS-SQL Server / 基础类
1.下面有表
name birth
a 1981
b 1981
c 1980
d 1981
e 1980
2.写一sql得到下面的结果
name1 name2 birth
a b 1981
a d 1981
b d 1981
c e 1980
下面是我的记过,老是去不了重复的:
select * from testj;
select distinct a.name,b.name,a.year,a.year-1980
from testj a,testj b where a.year=b.year and a.name!=b.name
order by a.name,b.name;
但是得到的结果是
a b 1981
和
b a 1981
是要去掉的。恳请高手帮忙?
啊,上面写错了
哈哈,我自己也错,好多人都搞错!
select a.name,b.name,a.birth,a.birth-1980
from #tb a left join #tb b on a.name<b.name
and a.birth=b.birth
where b.name is not null
用 < 或 >这样避免出现 a,b b,a的情况
还是不对啊,你怎么不自己运行下呢
建表语句
create table TESTJ
(
NAME VARCHAR2(10),
YEAR VARCHAR2(20),
BIRTH VARCHAR2(10)
)
恩,对了,谢谢你!
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
<folder state="unchecked&qu ......
需求如下:
学院 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 ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......
现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......