0

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

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 语句,但我似乎总是以这个错误结束:

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

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

4

1 回答 1

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;
于 2011-07-15T12:13:48.857 回答