I have a single table, my_table, with data like the following: I’m trying to write a query that would both sum the number of accesses GROUP BY’d fruit and the total number of access for each fruit, but only the accesses for levels less than 4. A result for that query would be: I tried the following self join, but
Tag: aggregate-functions
Select from many to many relations table
Given these tables: I would like to query scenarios with all the connected suites. results: **scenario** **suites** loginScenario loginSignup, endToEnd, smoke addToCart …
How calculate filtered by date aggregate sum after grouping by some column in SQL?
I have a table which contains payments received by person per date. I.e. We know how to calculate aggregate sum in SQL: We know how to calculate aggregated sum for some period of dates: Here is the question: what if I need last aggregate but I dont want to remove persons which never had payments on 12-12-2020? In other words,
Select rows in left join which depend on sum of a field in the other table?
Im trying to write a SQL left outer join query where the left rows are selected based on the sum of a field in rows in the other (right) table. The other table has an id field that links back to the …
Postgres: how to check for records in time buckets for multiple values
I have a POSTGRES table with roughly the following shape: sensor_id | recorded_at ———-+——————– A | 2020-01-01 00:00:00 A | 2020-01-01 00:03:00 B | …
SQLite How to calculate a difference between two variables of the same table [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago. Improve this question I am pretty new to SQL and I can’t figure out how to sum the amounts (in_amount – out_amount) per asset in the pantry considering
More than one row returned by a subquery when using STRING_AGG function
I get an error when trying to execute SELECT query in PostgreSQL 11 And authors_string should be fetched as a string value. It throwns an error ERROR: more than one row returned by a subquery used as an expression I guess it happens because of GROUP BY in subquery and can be handled with row_to_json function, but have no clue
Get data horizontal in SQL
I have this query: It’s returning: I’m trying to make it like this, if anyone could help me, thanks Answer You can pivot using conditional aggregation: It is unclear what the specific values are that go into each column.
How do you I calculate the difference between two timestamps in PostgreSQL?
I have a SELECT query to retrieve data I need. One of the needed data is a an “aggregate” function to select two timestamp dates and calculate the difference between them. Using several resources and websites, they all gave me save answer and it did not work: I’m getting an error on the “@”: syntax error at or near “@”
Postgres totals by classification per group
for example i have an orders table with a classification column. i want to get the total per classification for each city in a state for certain identified cities, for specific date. I have done the …