问题在第三行
SELECT
dboView_CheckSelfNoteUserId as UserId,
dboView_CheckSelfNoteUserName as UserName--缺少逗号
dboView_CheckSelfNoteUpdateTime as UpdateTime,
dboView_CheckSelfNoteClassHour as ClassHour,
dboView_CheckSelfNoteSelfPlanName as SelfPlanName,
dboView_CheckSelfNote[year] as [year],
dboView_CheckSelfNoteScore as Score,
dboView_CheckSelfNoteType as Type,
dboView_CheckSelfNoteIsFinish as IsClassHourGet,
CASE dboView_CheckSelfNoteIsFinish WHEN 0 THEN 0 WHEN 1 THEN dboView_CheckSelfNoteClassHour END AS ClassHourGet
FROM
dboView_CheckSelfNote
UNION
SELECT
dboBM_Staff_TblStaffId as UserId,
dboBM_Staff_TblUserName as UserName,
dboClassHourEx_TblTestTime as UpdateTime,
dboClassHourEx_TblClassHour as ClassHour,
dboClassHourEx_TblCourseName as SelfPlanName,
YEAR (
dboClassHourEx_TblTestTime
) AS [year],
dboClassHourEx_TblScore as Score,
dboClassHourEx_TblType as Type,
dboClassHourEx_TblIsFinish as IsClassHourGet,
CASE dboClassHourEx_TblIsFinish WHEN 0 THEN 0 WHEN 1 THEN dboClassHourEx_TblClassHour END AS ClassHourGet
FROM
dboClassHourEx_Tbl,
dboBM_Staff_Tbl
INNER JOIN dboBM_Staff_Tbl ON dboClassHourEx_TblUserId = dboBM_Staff_TblUserName
同时第二个查询多写了个dboBM_Staff_Tbl 用inner Join时候不需要在from後给多个表
建议给查询表加别名,这样看起来清爽直观些
写成
SELECTcsUserId as UserId,
csUserName as UserName,
csUpdateTime as UpdateTime,
csClassHour as ClassHour,
csSelfPlanName as SelfPlanName,
cs[year] as [year],
csScore as Score,
csType as Type,
csIsFinish as IsClassHourGet,
CASE csIsFinish WHEN 0 THEN 0 WHEN 1 THEN csClassHour END AS ClassHourGet
FROM
dboView_CheckSelfNote as cs
UNION
SELECT
stStaffId as UserId,
stUserName as UserName,
heTestTime as UpdateTime,
heClassHour as ClassHour,
heCourseName as SelfPlanName,
YEAR ( heTestTime) AS [year],
heScore as Score,
heType as Type,
heIsFinish as IsClassHourGet,
CASE heIsFinish WHEN 0 THEN 0 WHEN 1 THEN heClassHour END AS ClassHourGet
FROM
dboClassHourEx_Tbl as he
INNER JOIN dboBM_Staff_Tbl as st ON heUserId = stUserName
两表的数据连接sql语句,假如有a表和b表:select from a,b 这样就可以查询两个表的所有数据!
也可以添加条件 select from a,b where (条件)!
如果只查询两个表有对应关系的资料,则用内连接:
select
from
table1
inner
join
table2
on
table1id=table2id;
如果查询表1中有的资料,表2中若有则也显示,则使用左连接:
select
from
table1
left
join
table2
on
table1id=table2id;
不管两个表是否有关联,所有资料都显示,则用外链接:
selecg
from
table1
outer
join
table2
on
table1id=table2id;
以上就是关于sql 把两张结构相似的表拼接为一个视图,以下为我写的sql全部的内容,包括:sql 把两张结构相似的表拼接为一个视图,以下为我写的sql、求赐我一条SQL语句,两表数据拼接SQL语句怎么写、连接两表查询结果的SQL语句等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)