2
select (select Nombre 
        from Pacientes 
        where idPacientes= any(select idPaciente 
                                from Citas 
                                where Dias_idDia= any(select idDia 
                                                      from Dias 
                                                      where fecha = '2013-10-15'))) as 'Nombre',horaInicio, horaTermino,actividad,observacion,recordar,ciudad,tipoCita 
from Citas 
where Dias_idDia = any (select idDia 
                        from Dias 
                        where fecha='2013-10-15')
order by horaInicio;

我有错误 1242,如果有人可以帮助解决这个问题,因为它给我的系统带来了很多麻烦。泰

4

2 回答 2

4

子查询的行数不正确:

ERROR 1242 (ER_SUBSELECT_NO_1_ROW) SQLSTATE = 21000 消息 = “子查询返回多于 1 行” 对于子查询必须最多返回一行但返回多行的语句,会出现此错误。考虑以下示例:

SELECT * FROM t1 WHERE column1 = (SELECT column1 FROM t2);

如果 SELECT column1 FROM t2 只返回一行,则前面的查询将起作用。如果子查询返回多于一行,则会出现错误 1242。在这种情况下,查询应重写为:

SELECT * FROM t1 WHERE column1 = ANY (SELECT column1 FROM t2);

参考

于 2013-10-16T08:40:46.943 回答
2
   select (select Nombre 
       from Pacientes 
       where idPacientes in (select idPaciente 
                            from Citas 
                            where Dias_idDia in (select idDia 
                                                  from Dias 
                                                   where fecha = '2013-10-15'))) as
  'Nombre',horaInicio, horaTermino,actividad,observacion,recordar,ciudad,tipoCita 
   from Citas 
   where Dias_idDia in (select idDia 
                    from Dias 
                    where fecha='2013-10-15')
   order by horaInicio;
于 2013-10-16T09:20:41.940 回答