How to call the value of a Subquery inside another Subquery being that they are in the same View

1

I have a View with several Subqueries, one of them should be used to generate another Subquery within the View itself but I'm getting error, eg:

(SELECT COUNT(0)
   FROM 'LICENCAS'
  WHERE ('LICENCAS'.'FK_PEDIDO' = 'A'.'FK_PEDIDO') AND Dia_Corrido_Assinatura > 'LICENCAS'.'CICLO') AS 'DownloadCount',
(SELECT CEILING((TIMESTAMPDIFF(SECOND, 'A.''ASSINATURA_DATA_INICIO', NOW()) / 86400))) AS 'Dia_Corrido_Assinatura',
FROM 'N_ASSINATURAS' 'A'

I'm having trouble with Subquery DownloadCount because inside it I call the value of Subquery Dia_Corrido_Assinatura however I get the message:

  

Error Code: 1247. Reference 'Script_Day_day' not supported (forward reference in item list)

I understand that since it is a Subquery, it may not have even been generated to be called, are there any options on top of that?

EDIT: I've already tried to change order by putting the sub 'Script_Day_Day' first, but continue with the same error.

    
asked by anonymous 05.01.2018 / 19:42

1 answer

0

You can use your subselect on days from. For example:

SELECT 
--esse é seu subselect download
(SELECT COUNT(0)
   FROM 'LICENCAS'
  WHERE ('LICENCAS'.'FK_PEDIDO' = 'A'.'FK_PEDIDO') AND tab.dias_ocorridos > 'LICENCAS'.'CICLO') AS 'DownloadCount'
  tab.dias_ocorridos
FROM (SELECT referencia_id, 10 dias_ocorridos FROM N_ASSINATURAS) tab, N_ASSINATURAS
WHERE
N_ASSINATURAS.referencia_id = tab.referencia_id

Or make a function that returns this value, or another separate view. You can not create columns within the same select clause. Type this:

 select 1 um,
           2 dois,
           um+dois as soma
    from dual

Does not work

    
05.01.2018 / 22:38