Crystalguru
Technical User
Hello,
I am trying to complete the following SQL.
SELECT DISTINCT
1 AS SOLVE_ORDER,
MIN(COM.REGION) AS REGION,
COM.PROPERTY_ID AS PROPERTY_ID,
MIN(COMS.PROPERTY_NAME) AS PROPERTY_NAME,
MIN(COM.PROPERTY_UNIT_COUNT) AS PROPERTY_UNIT_COUNT,
TTYPE.DATE_DAY AS DATE_DAY,
SUM(TTYPE.OCCUPIED) AS OCCUPIED,
sum(occupied)/sum(distinct property_unit_count)*100 AS WA_OCCUPANCY,
TDEF.TIER AS TIER
FROM
COMMUNITIES COM
TIME_SERIES_BY_UNIT_TYPE TTYPE ,
TIERDEFS TDEF
WHERE
COM.PROPERTY_ID = TTYPE.PROPERTY_ID
AND TRIM(COM.PROPERTY_REGION) = TRIM(TDEF.REGION)
AND TTYPE.DATE_DAY >= TO_DATE('1/1/2002','MM/DD/YYYY')
AND TO_CHAR(TTYPE.DATE_DAY,'DY') = 'SUN'
AND COM.PROPERTY_ACTIVE_FLAG = 1 AND
TTYPE.DATE_DAY BETWEEN TDEF.BEGINDATE AND ENDDATE
and
sum(occupied)/sum(distinct property_unit_count)*100 between tdef.tierlow and tdef.tierhigh
GROUP BY COMMUNITIES.PROPERTY_ID, TIME_SERIES_BY_UNIT_TYPE.DATE_DAY, TDEF.TIER
My problem in within the WHERE statement on the --sum(occupied)/sum(distinct property_unit_count)*100--a group function is not allowed in the where statement. I am not sure how to do the comparision now?? Any ideas?
thanks carrie
I am trying to complete the following SQL.
SELECT DISTINCT
1 AS SOLVE_ORDER,
MIN(COM.REGION) AS REGION,
COM.PROPERTY_ID AS PROPERTY_ID,
MIN(COMS.PROPERTY_NAME) AS PROPERTY_NAME,
MIN(COM.PROPERTY_UNIT_COUNT) AS PROPERTY_UNIT_COUNT,
TTYPE.DATE_DAY AS DATE_DAY,
SUM(TTYPE.OCCUPIED) AS OCCUPIED,
sum(occupied)/sum(distinct property_unit_count)*100 AS WA_OCCUPANCY,
TDEF.TIER AS TIER
FROM
COMMUNITIES COM
TIME_SERIES_BY_UNIT_TYPE TTYPE ,
TIERDEFS TDEF
WHERE
COM.PROPERTY_ID = TTYPE.PROPERTY_ID
AND TRIM(COM.PROPERTY_REGION) = TRIM(TDEF.REGION)
AND TTYPE.DATE_DAY >= TO_DATE('1/1/2002','MM/DD/YYYY')
AND TO_CHAR(TTYPE.DATE_DAY,'DY') = 'SUN'
AND COM.PROPERTY_ACTIVE_FLAG = 1 AND
TTYPE.DATE_DAY BETWEEN TDEF.BEGINDATE AND ENDDATE
and
sum(occupied)/sum(distinct property_unit_count)*100 between tdef.tierlow and tdef.tierhigh
GROUP BY COMMUNITIES.PROPERTY_ID, TIME_SERIES_BY_UNIT_TYPE.DATE_DAY, TDEF.TIER
My problem in within the WHERE statement on the --sum(occupied)/sum(distinct property_unit_count)*100--a group function is not allowed in the where statement. I am not sure how to do the comparision now?? Any ideas?
thanks carrie