How to convert sql to influxdb

how can i write a query like this

value total-sum rate
red 10 100 0.1
blue 50 100 0.5
yellow 40 100 0.4

i want to calculate totalsum and rate

Hey @besiktas_sk

Could you give us a little more of what you have?
A sample of your database would help. Are you using V1 or V2 (or V3)?
What do you mean by “How to convert sql to influxdb”? Do you already have an SQL query? If yes please share it.

Regards

i’m sorry i’am new to influxdb


i have a table like this, i want to calculate each symbol sum of value and each symbols within rate ( sumofsymbol / total_sumofallsymbols)
i cant find sql equavalent of window functions in influx

@besiktas_sk
Are you using V1 or V2 (or V3)?
What is the query you used to generate the screenshot you shared?

InfluxDB v3 (Cloud only at the moment) allows you to use SQL to query InfluxDB. From your posts, if you already know SQL, then I suggest you go here and choose Serverlesss to give it a test run.

Yes, you can use SQL to create such a table in our V3, are you using InfluxDB serverless or open source or another version ? In your screenshot attached the schema doesn’t match what you asked in original question. First step would be to write to the bucket by using line protocol or API to add the necessary data, for e.g. For your measurement, create Tag: value (e.g., red, blue, yellow) Fields: total_sum (the total sum), rate (the rate) and then you can write SQL query to calculate total sum and rate.

thanks for reply
this is my query i use it on grafana dashboard
i get total sum by symbol from selected time frame but i need
total sum of all data also to calculate
sum_of_symbol / total_sum_all = each symbol rate

from(bucket: “wss1”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “cash_flow”)
|> filter(fn: (r) => r[“_time”] >= v.timeRangeStart and r[“_time”] <= v.timeRangeStop )
|> group(columns: [“symbol”])
|> sum(column: “_value”)
|> map(fn: (r) => ({
_value: r._value,
symbol: r.symbol
}))
|> yield()

thanks for reply,
i’m using open source version 2.7.4
first example is my final result i want to establish, attached schema is that how i store data.
i’m already using api to store data.