MySQL:JOIN语法+在choices = Operand Error中选择

时间:2011-07-14 23:42:56

标签: mysql select join operand

我一直在努力解决这个问题。这是:

select First10.mal, Last10.family_name,
(select * from gender2
JOIN
(select * from status) as Mix1
JOIN
(select * from age as Mix2 order by rand() limit 10) as Mix3
JOIN
(select incidentid from incidentid2 as Mix4)
as Mix5 where data='mal' and incidentid='6' and status IN ('inj','ali') and age IN ('NULL','0-17') 
order by rand() limit 100)
from ( select fn.mal, @fns := @fns + 1 as Sequence
from ( select mal from fnames where mal IS NOT NULL order by rand() limit 100) fn,
(select @fns := 0 ) vars ) First10
JOIN
( select ln.family_name, @lns := @lns + 1 as Sequence
from ( select family_name from lastnames order by rand() limit 100 ) ln,
(select @lns := 0 ) vars ) Last10
ON First10.Sequence = Last10.Sequence;

我的目标是插入一个表格,该表格会显示随机的名字,姓氏,性别,状态,年龄和事件ID。我已经尝试了很多方法来重写这个脚本,包括分离select语句,但我似乎总是遇到这个错误:

  

ERROR 1241(21000):操作数应包含1列

请告诉大家,这一直在给我压力一段时间......这可能是一个非常简单的答案,但我只是让自己更加困惑。如果您需要任何澄清,请询问。

1 个答案:

答案 0 :(得分:0)

好吧,看起来好好睡了一晚并得到朋友的帮助,我得到了这个查询。对于那些正在寻找类似问题答案的人来说,以下是我的工作方式:

select mal,family_name,data,age,status,incidentid
from ( select fn.mal, @fns := @fns + 1 as Sequence
from ( select mal from fnames where mal IS NOT NULL order by rand() limit 100) fn,
(select @fns := 0 ) vars ) as FN
INNER JOIN
(select ln.family_name, @lns := @lns + 1 as Sequence
from ( select family_name from lastnames order by rand() limit 100 ) ln,
(select @lns := 0 ) vars ) as LN
INNER JOIN
(select * from gender2) as Mix0
INNER JOIN
(select * from status) as Mix1
INNER JOIN
(select * from age as Mix2 order by rand() limit 3) as Mix3
INNER JOIN
(select incidentid from incidentid2 as Mix4)
as Mix5 where data='mal' and incidentid='6' and status IN ('inj','ali') and age IN ('NULL','0-17') 
order by rand() limit 100;