In SQL, 3 tables joined together, retreving 3 values: value, time, value_name. Value is the one I want averaged by day, time is in datetime format on about 10 mins – this one I want it to be converted in day to day, resulting in one row for every day – and my value_name witch cand be any selected value.
Here is my syntax:
select time.entry_time, value_type.value_name,
avg(value.value) AVG_VALUE
FROM Value
inner join time on value.time_id = time.id
inner join value_type on value.type_id = value_type.id
WHERE value_type.value_name = 'CUSTOM'
GROUP BY DATEPART(DAY, time.entry_time)
Here I get an error:
Column
time.entry_timeis invalid in the select list because it is not contained in either an aggregate function or theGROUP BYclause.
Can you please help me with this syntax?
Two problems:
You select
time.entry_time, but are grouping onDATEPART(DAY, time.entry_time). Which entry time do you want? Did you mean to selectDATEPART(DAY, time.entry_time)instead?You are not grouping by
value_type.value_name. You will need to add this to theGROUP BYclause. (Yes, even though there will only be one value ‘CUSTOM’).Try: