none
Sub-query doubt RRS feed

  • Question

  • I have to write a query to get the count hospital having the total number of beds less than 1000. But here is the trick total number of beds is not a column but SUM of different columns.  

    So I know I would need a subquery to get total but I don't understand which clause  and how it would receive it?

    Currently, I have drafted this query.

    select count([C1_Record ID])
    from [dbo].[GHI_hospitals_PriorYear_EditTemp]
    where [C4_Country]='Brazil'
    AND 
    (
    select SUM(CAST ([C74_AMBULATORY BEDS-SURGERY/SHORT STAY (CAMAS EN ATENCION] AS int) 
    + CAST ( [C76_AMBULATORY BEDS-BIRTHING RECUPERATION (CAMAS EN AMBULATORIO]AS int)
    + CAST ([C75_AMBULATORY BEDS-LABOR (CAMAS EN AMBULATORIO-TRABAJO DE PARTO] AS int) 
    + CAST ( [C77_AMBULATORY BEDS - INTENSIVE CARE (CAMAS EN AMBULATORIO]AS int) 
    + CAST ([C78_AMBULATORY BEDS - INTERMEDIARY CARE (CAMAS EN AMBULATORIO] AS int)
    + CAST ( [C79_AMBULATORY BEDS - OTHER (CAMAS EN AMBULATORIO - OTRAS] AS int)
    from [dbo].[GHI_hospitals_PriorYear_EditTemp]
    where [C4_Country]='Brazil'

    ) AS TOTAL < 1000

    Please help to clarify this doubt.


    • Edited by MaddyAtWork Wednesday, August 3, 2016 6:54 PM
    Wednesday, August 3, 2016 6:53 PM