sql 语句问题 急!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/27 23:41:27


create table users(
uid int identity(1,1) primary key ,
uname varchar(50) not null,
uxue int not null,
ulan int not null,
uzhuangtai int references uzhuangtai(zid) not null
)

create table uzhuangtai(
zid int identity(1,1) primary key ,
zwq int references wuqi(wid),
zyifu int references yifu(yid),
zxie int references maozi(mid),
)
create table wuqi(
wid int identity(1,1) primary key ,
wname varchar(50),
wgong int not null,
)
create table yifu(
yid int identity(1,1) primary key ,
yname varchar(50),
yfang int not null,
)
create table maozi(
mid int identity(1,1) primary key ,
mname varchar(50),
mfang int not null,
)
uzhuangtai是状态表 是 人物的状态。状态里包括 武器 衣服 鞋子。

这状态表 是为users提供的 好比user里有个叫李逍遥的人物 那么他的衣服武器鞋子可以通过 uzhuangtai 查到。而状态里分别有不同表里的数据,比如字段zwq 是wuqi表里的id为1 的那个武器。他的名字叫木剑。
我现在想查到
user表里 id 为1 的那个人物的名字,血,蓝,武器,

select u.uname,u.uxue,u.ulan,w.wname,y.yname,m.mname
from users u,uzhuangtai z,wuqi w,yifu y,maozi m
where u.uzhuangtai=z.zid and z.zwq=w.wid and z.zyifu=y.yid and z.zxie=m.mid

不知道你需要什么效果
1
select users.uname as 名字,users.uxue as 血, users.ulan as 蓝,
uzhuangtai.zwq, uzhuangtai.zyifu,uzhuangtai.zyifu,uzhuangtai.zxie
from users inner join uzhuangtai on users.uzhuangtai=uzhuangtai.zid
类似的在每个列后加上你想看的名字 好像汉字要加上引号
这样就成了
名字 血 蓝
李逍遥 120 75 。。。。。

2 select users.uname||' 名字',users.uxue||' 血', users.ulan,
uzhuangtai.zwq, uzhuangtai.zyifu,uzhuangtai.zyifu,uzhuangtai.zxie
from users inner join uzhuangtai on users.uzhuangtai=uzhuangtai.zid

类似这样 就有这种效果

李逍遥 名字 120 血 .....
||是oracle的用法 如果你是其它数据库就换一下 sql好像是+吧
你想要那种效果试试看