 
                                                    --The second SELECT statement (get the monthly data and keep it monthly)
 
-SELECT DatasetAcronym,AttributeName, InstanceName,AggregationStatisticCV,IntervalTimeUnitCV,UnitNameCV,
+SELECT ResourceTypeAcronym,AttributeName, InstanceName,AggregationStatisticCV,IntervalTimeUnitCV,UnitNameCV,
 YearType,strftime('%m/%Y', DateTimeStamp) as YearMonth, TimeSeriesValueID,count(value) As CountDays,
 
 

LEFT JOIN "Instances" 
ON "Instances"."InstanceID"="Mappings"."InstanceID"

LEFT JOIN "DataValuesMapper" 
ON "DataValuesMapper"."DataValuesMapperID"="Mappings"."DataValuesMapperID"

LEFT JOIN "ScenarioMappings"
ON "ScenarioMappings"."MappingID"="Mappings"."MappingID"


AND "AttributeNameCV"='Flow'

--AND ResourceTypeAcronym='BearRiverCommission'


-- It is best to filter by day or month values. 
--Then you can use the “Having” clause below for daily but need to comment it for monthly
AND IntervalTimeUnitCV='month'

GROUP BY ResourceTypeAcronym,AttributeName,InstanceName,YearType,YearMonth

-- use this only if converting from daily to monthly (otherwise, months wont show up because their count is just 1)
--The use of "HAVING" clause enables you to specify conditions that filter which group results appear in the final results.
