表dfgg_user
姓名 上级
xx 甲
bb 乙表 题库 table_no主键
table_no 姓名
1 xx
2 bb表 成绩 id为主键 _no与题库表中的table_no对应 意思是题库中每一个题对应的成绩
id _no year
69 1 2010
70 2 2010现在要查询有2010年分数的人员的姓名与上级 怎么查啊select a.姓名,a.上级 from dfgg_user a,成绩 b,题库 c where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名) order by a.部门查不到啊
姓名 上级
xx 甲
bb 乙表 题库 table_no主键
table_no 姓名
1 xx
2 bb表 成绩 id为主键 _no与题库表中的table_no对应 意思是题库中每一个题对应的成绩
id _no year
69 1 2010
70 2 2010现在要查询有2010年分数的人员的姓名与上级 怎么查啊select a.姓名,a.上级 from dfgg_user a,成绩 b,题库 c where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名) order by a.部门查不到啊
from dfgg_user a
where exists(
select 1 from 题库 b where b.姓名=a.姓名
and exists(
select 1 from 成绩 c where c._no=b.table_no and c.[year]=2010
)
)
from dfgg_user a,成绩 b,题库 c
where (b.[year]= '2010' and b._no = c.table_no and a.姓名 = c.姓名)
order by a.部门看不出大的错误,修改一个小错误
insert into dfgg_user values('xx', '甲')
insert into dfgg_user values('bb', '乙')
create table 题库(table_no int,姓名 varchar(10))
insert into 题库 values(1, 'xx')
insert into 题库 values(2, 'bb')
create table 成绩(id int,_no int,[year] varchar(10))
insert into 成绩 values(69 ,1 ,'2010')
insert into 成绩 values(70 ,2 ,'2010')
goselect a.姓名,a.上级 from dfgg_user a,成绩 b,题库 c where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名)drop table dfgg_user ,题库,成绩/*
姓名 上级
---------- ----------
xx 甲
bb 乙(所影响的行数为 2 行)
*/
a.*
from
dfgg_user a
where
exists(select 1 from 题库 b where b.姓名=a.姓名 and exists(select 1 from 成绩 c where c._no=b.table_no and c.[year]=2010))
select
a.姓名,a.上级
from
dfgg_user a,成绩 b,题库 c
where
b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名
姓名 上级
xx 甲
bb 乙
create table dfgg_user
(
[name] varchar(50),
parent varchar(50)
)
insert into dfgg_user([name],parent)
(
select 'xx','甲' union
select 'bb','乙'
)表 题库 table_no主键
table_no 姓名
1 xx
2 bb
create table superscription
(
table_no int,
[name] varchar(50)
)
insert into superscription(table_no,[name])
(
select 1,'xx' union
select 2,'bb'
)表 成绩 id为主键 _no与题库表中的table_no对应 意思是题库中每一个题对应的成绩
id _no year
69 1 2010
70 2 2010
create table score
(
id decimal,
_no int,
[year] datetime
)
insert into score(id,_no,[year])
(
select 69,1,'2010' union
select 70,2,'2010'
)现在要查询有2010年分数的人员的姓名与上级 怎么查啊select a.姓名,a.上级 from dfgg_user a,成绩 b,题库 c
where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名)
order by a.部门查不到啊
select * from dfgg_user
go
select * from superscription
go
select * from score
go
select u.name,d.parent from score s
left join superscription u on s._no=u.table_no
left join dfgg_user d on u.[name]=d.[name]
go
and a.ujob like 'GL%' and ( a.upmanager like '7116' )select a.姓名,a.部门 from dfgg_user a,成绩 b,题库 c where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名) and a.工种 like 'GL%' and ( a.上级 like '7116' ) order by a.部门
select a.姓名,a.部门 from dfgg_user a,成绩 b,题库 c where (b.year= '2010' and b._no = c.table_no and a.姓名 = c.姓名) and a.工种 like 'GL%' and ( a.上级 like '7116' ) order by a.部门
或者把varchar型改为nvarchar型再试试.
create table dfgg_user(姓名 nvarchar(10),上级 nvarchar(10))
insert into dfgg_user values(N'xx', N'甲')
insert into dfgg_user values(N'bb', N'乙')
create table 题库(table_no int,姓名 nvarchar(10))
insert into 题库 values(1, N'xx')
insert into 题库 values(2, N'bb')
create table 成绩(id int,_no int,[year] nvarchar(10))
insert into 成绩 values(69 ,1 ,N'2010')
insert into 成绩 values(70 ,2 ,N'2010')
goselect a.姓名,a.上级 from dfgg_user a,成绩 b,题库 c where (b.[year]= N'2010' and b._no = c.table_no and a.姓名 = c.姓名)drop table dfgg_user ,题库,成绩/*
姓名 上级
---------- ----------
xx 甲
bb 乙(所影响的行数为 2 行)
*/