项目信息表 proinfo 表有游散列,项目id,项目性质,项目来源,均为guid类型。如下:id proNature proSource项目类型信息表 proTypeInfo 有字段如下。id proTypeName type id为guid,proTypeName为项目类型名称,type有两值,1为项目类型,2为项目来源。proTypeName 为表proinfo 的外键。
现在要查询proinfo中的id,proNature名称和proSource名称???
现在要查询proinfo中的id,proNature名称和proSource名称???
一个string,一个guid,你怎么个外键法?
应该是proSource为proTypeInfo的外键吧?select proinfo.id,proinfo.proNature, proTypeInfo.proTypeName
from proinfo
inner join proTypeInfo on proTypeInfo.id = proinfo.proSource
错了,proinfo 表中的proNature proSource 都为外键,指向proTypeInfo 表中的id。。
看好了,是proinfo 表中的proNature proSource 都为外键,都指向proTypeInfo 表中的id。
from proinfo a
left join proTypeInfo b on a.id=b.proNature and b.type=1
left join proTypeInfo c on a.id=c.proSource and b.type=2TRY
from proinfo a
left join proTypeInfo b on b.id=a.proNature and b.type=1
left join proTypeInfo c on c.id=a.proSource and c.type=2
select a.id,b.proTypeName as proNature ,c.proTypeName proSource
from proinfo a
left join proTypeInfo b on b.id=a.proNature and b.type=1
left join proTypeInfo c on c.id=a.proSource and c.……
[/Quote谢啦。。自己建了两张表试了试,结果不错。。