4

我正在尝试创建一个查询来搜索所有具有类似属性的记录,如下所示:

select * from table_A 
where fullname like in (select firstname from employees where X)

唯一的问题是这只是我的伪代码,我实际上是在对许多表进行排序,所以我目前的真实查询看起来像:

select * from devices 
where devicename like in (select X from X1 where T in (select T from T1 where Y in     (select Y from Y1 where Z in (select Z from Z1 where AreaName = '74';

我正在尝试使用 join 命令,但对如何将其应用于这种情况感到非常困惑。

4

5 回答 5

1

干得好 ....

SELECT D.* 
from Devices D
    inner join X1 X on D.devicename like X.X 
    inner join  T1 T on T.T = X.T
    inner join Y1 Y on Y.Y = T.Y
    inner join Z1 Z on Y.Z = Z1.Z AND Z.Areaname = '74';
于 2012-11-20T08:56:44.700 回答
1

尝试:

SELECT d.*
  FROM devices d
 INNER JOIN X1 ON d.devicename like '%'||x1.X||'%'
 INNER JOIN T1 ON x1.T = T1.T
 INNER JOIN Y1 ON T1.Y = Y1.Y
 INNER JOIN Z1 ON Y1.Z = Z1.Z
 WHERE Z1.AreaName = '74'
于 2012-11-20T08:38:21.073 回答
0

“join”命令运行两个表的叉积,然后只选择公共列名具有相同值的元组/行。

因此,对于您的查询:

select * from table_A
where fullname like in (select firstname from employees where X)

将会:

select * from table_A
left join employees
on table_A.fullname = employees.firstname
where X
于 2012-11-20T07:59:42.727 回答
0

好的,我用 Join 语法给你第二个查询(好吧,我尝试):

select * from  Z1 Z1_1 
    JOIN Y1 Y_1 ON Y_1.Z=Z1_1.Z 
    JOIN T1 ON T1.Y=Y_1.Y 
    JOIN X1 X1_2 ON X1_2.T=T1.T 
    JOIN devices  d ON d.devicename=X1_2.X
    where Z1_1.AreaName = '74';
于 2012-11-20T07:55:48.953 回答
0

尝试这个:

SELECT d.*
FROM devices d
INNER JOIN X1 ON d.`like` = x1.X
INNER JOIN T1 ON x1.T = T1.T
INNER JOIN Y1 ON T1.Y = Y1.Y
INNER JOIN Z1 ON Y1.Z = Z1.Z
WHERE Z1.AreaName = '74'
于 2012-11-20T07:56:02.627 回答