私のテーブル:
Dataid 日付 register_type read_value 77 2012-08-15 第20世代 77 2012-08-15 ソーラー 48 77 2012-08-16 第39世代 77 2012-08-16 第22世代 80 2012-07-11 第11世代 80 2012-07-12 ID23 91 2012-02-01 ID 4 91 2012-02-01 gen 59 91 2012-02-08 第18世代
毎日、read_values
「gen」のみの合計を実行したいと思いregister_type
ます。基本的に、クエリが次のテーブルを返すようにします。
dataid 日付 Daily_value 77 2012-08-15 20.00 77 2012-08-16 61.00 80 2012-07-11 11.00 91 2012-02-01 59.00 91 2012-02-08 18.00
次のクエリを試しましたが、うまくいきません。
select
dataid,
date_trunc('day', timestamp_localtime) as truncated_day,
substring(cast(date_trunc('day', timestamp_localtime) as text)
from 1 for 10) as date,
sum(read_value) as daily_gen
where register_type like ‘%gen%’
from table
group by dataid, date_trunc('day', timestamp_localtime)
order by dataid, truncated_day
このクエリをどのように記述しますか?