How to find last(sum(count)) in influxdb? - influxdb

Here in my db measurement, the tags are "source", "edition", "date" and the field is "count".
Each source has multiple editions. I am pushing data on the basis of editions.
I want the sum of editions for each source. I can get it by the normal query.
But here I want this for multiple dates. It is also possible by using nested functions or function of functions.
select mean(sum),last(sum) from (select sum(count) from epaper_edition where (date='2017-11-03' or date='2017-11-04' or date='2017-11-05' or date='2017-11-06') group by date,source) group by source
last() function is based on timestamp.
The last(sum(count)) results in random sum(count), not the Last one.
I have a solution by using a separate query sum(count) for the last date. I need it on one query.
Thanking you advance for giving me a better solution for this.

If you want sums of individual editions per source, you need to group by edition as well as source.
select mean(sum),last(sum)
from (select sum(count) from epaper_edition where (date='2017-11-03' or date='2017-11-04' or date='2017-11-05' or date='2017-11-06')
group by date, source, edition)
group by source, edition

Related

How to compare Individual data to aggregate group by in Google Query (SQL)?

I have a table like this, with the current table in blue, and the desired results highlighted in yellow:
And my goal is to set up a query in Google Sheets using their built-in =QUERY() function (note: based on the Google's own Query language, which is very similar to SQL) that can essentially do this entire table, without adding extra formulas. I know how to find the monthly averages separately, in a style like
SELECT month(DateRun), average(metric) GROUP BY month(DateRun)
But how could you have it so it's like
SELECT AdID, DateRun, Metric, average(Metric for Associated Month), IndividualMetric - AverageForMonth
I have tried to find it on my own, but have not been able to find a resource that I'm able to transform for my own usage.
I learned sub-queries a while back, and have a feeling that maybe the answer to this but I am very lost.
Please let me know if I can provide any additional information.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(MONTH(B2:B),
QUERY(B2:C, "select month(B)+1,avg(C) group by month(B)"), 2, 0)))
and:
=ARRAYFORMULA(IF(B2:B="",,C2:C-D2:D))
UPDATE:
You seem to be looking for a window average:
select
AdID,
DateRun,
Metric,
avg(Metric) over(
partition by Metric, date_trunc(DateRun, month)
) month_avg_metric,
Metric - avg(Metric) over(
partition by Metric, date_trunc(DateRun, month)
) diff_with_month_avg_metric
from mytable
The last but one column in the resultset gives you the average of the metric for the on-going month, and the last column computes the difference between the current metric and its monthly average.

Sort TFS Query By Itaration Start Date

I have TFS/AzureDevOps query which is sorted by Iteration Path .
I need to sort it by Iteration Start Date.
I dont see any option on the Sorting Page or in the query page to sort like this.
I tried sorting by iteration ID but the iteration were not created in order .
WIQL Code
SELECT
[System.IterationPath],
[Prod.Versions],
[System.Id],
[Prod.Territory],
[Prod.Customer],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitems
WHERE
[System.TeamProject] = #project
AND [System.WorkItemType] = 'Feature'
AND [Prod.Versions] >= '9.0'
AND [System.IterationPath] <> 'Machine'
AND [System.AreaPath] UNDER 'Machine\Development'
ORDER BY [System.IterationId],
[System.Id]
i would like it to be ordered like the following (this is from the setting page of the project in AzureDevops Server 2019 ):
We have adopted a naming convention for our iterations that uses the start date of the iteration as the name in order to achieve this.
So the iterations are named like:
2019.08.12
2019.08.26
not ideal, and I would love to see a option to include the iteration's start date a column for this very reason. Hopefully we will see a better answer soon.
Sorry, TFS work item query not support to filter Iteration using Start/End Dates.
There is a similar question here: TFS show iteration Start and End Date on PBI
Since using a name contain iteration date is not a solution for you. As another workaround, you could try get Iterations in specific Start/End dates using TFS API. Some thing maybe helpful for your reference.
Besides, in each collection database there is a table called "tbl_nodes" that holds the start-date and the end-date.
Writing a warehouse adapter that actually picks up these dates and saves them to the warehouse. Note do not write or change anything directly in database which may lose official support.
For query work item using Iteration Start/End Dates scenario, please submit it to User Voice site at: https://developercommunity.visualstudio.com/spaces/21/visual-studio-team-services.html?type=idea Microsoft engineers will evaluate any feature request seriously.

Google Data Studio: how to create time series chart with custom Big Query query

I have a Data Studio report with a Time Series added. The data source is from a custom query using the Big Query connector:
select user_dim.app_info.app_version, count(1) as count
from [my_app_domain_ANDROID.app_events_20160929]
group by 1
According to the Data Studio documentation at: https://support.google.com/360suite/datastudio/answer/6370296?hl=en
BigQuery supports querying across multiple tables, where each table has a single day of data. The tables have the format of YYYYMMDD. When Data Studio encounters a table that has the format of YYYYMMDD, the table will be marked as a multi-day table and only the name prefix_YYYYMMDD will be displayed in the table select.
When a chart is created to visualize this table, Data Studio will automatically create a default date range of the last 28 days, and properly query the last 28 tables. You can configure this setting by editing the report, selecting the chart, then adjust the Date Range properties in the chart's
However, in the Time Series Properties DATA tab, there no no valid "Time Dimension" to select. According to the documentation, I should not need to select a Time Dimension. It should query the right table automatically.
Something I am not understanding yet?
There are 2 issues with the query in the question:
To get a time series, you'll need to add a time based column to the custom query.
For example:
SELECT created_at, COUNT(*) c
FROM [githubarchive:day.20160930]
WHERE type='WatchEvent'
GROUP BY 1
Data Studio won't do the 28 day expansion with custom queries. To get the expansion featured in the documentation, you need to point to an actual table (and Data Studio will figure out the prefix and date expansion).
I left a working example at:
https://datastudio.google.com/open/0ByGAKP3QmCjLSjBPbmlkZjA3aUU

can grafana group by multiple columns when work with influxdb

when I use influxdb as the datasource, In the graph metrics define, I find that if I add a column after the "and" label, (like: latency_scope, type), data response is correct but legend display undefine, and there is no date display on the dashboard.
raw query is like this, however, it does not work.
"select latency_scope, uri, sum(sum_count) from "latency" where $timeFilter group by time($interval), latency_scope, uri fill(0) order asc"
Can grafana make multiple group by?
thx
I just checked the code, and that's true it does not support multiple group by, but it is not difficult to modify the source code to support.

Crystal Reports parameterized queries

The company I work for is using MacolaES for an ERP system. The SQL Server database is structured such that when things are no longer considered active, they are moved from a set of "active" tables to a set of "history" tables. This helps to keep the "active" tables small enough that queries return quickly. On the flip side, the history tables are enormous. The appropriate columns are indexed in these tables, and if you query for something specific it returns quickly.
The problem is when you make a Crystal Report, which is prompting the user for a parameter. For reasons not known to me, Crystal parameters are not translated into SQL parameters, so you end up with queries selecting everything from the order header history table inner joined to everything in the order lines history table, which results in over 8 million rows.
Is there a way to get Crystal Reports to use the parameters in the SQL query instead of loading all the records and filtering after the fact? I read somewhere that a stored procedure should work, but I'm curious if an ordinary parameterized query is possible in the interest of saving my time.
Here is the selection formula:
(
trim({Orderheader.ord_no}) = {?Order No}
)
and
(
{Orderheader.ord_type} = 'O'
)
and
(
{orderlines.ord_type} = 'O'
)
In Crystal Reports top menu go to Report / Selection Formulas / Record... There you can add a formula similar to:
{table.field1} = {?Parameter1} and {table.field2} = {?Parameter2}
That will add the condition to the where statement of the SQL query that the report will use to pull the rows.
To verify what is the condition in the where statement that the report is using to pull the data you can go to the menu database / Show SQL Statement. That way you can verify that the report is using the parameters in the filter.
Crystal Reports 8.5 User Guide mention the following tips:
To push down record selection, you
must select “Use Indexes or Server for
Speed” in the Report Options dialog
box (available on the File menu).
In record selection formulas, avoid data
type conversions on fields that are
not parameter fields. For example,
avoid using ToText( ) to convert a
numeric database field to a string
database field.
You are able to push down some record selection formulas
that use constant expressions.
Your formula has a TRIM function on a field. The function against the field does not allow Crystal to push the formula to the database because is not a constant expression.
If you really need to trim the order number field you should do it using SQL Expressions.
References:
Check out this article.

Resources