I want the count adding one only when the value has not been show before. The base table is: The goal is: I am thinking to compare the current row with all previous rows, but I have difficulty to call all previous rows. Thank you! Answer Several different ways to accomplish this. I guess you’ll get to p…
Tag: greatest-n-per-group
Oracle SQL: how to show only one max per group
Hi everyone first thanks for your time. I have this data Data: And I have to obtain the max values of everygroup, if there is one group that has two same max values like A 40 23/56/1982 A 40 31/4/…
How do I get the matching id for every record?
My table is called platform_statuses, here is its schema: And this is my query, I would like to also get the matching id for the returned records. Also note that the abs function you see in the query is a custom one I got off this answer. Here is its definition: Answer I understand that, for each account and …
Is it Possible to Merge Rows in SQL from Just One Column?
I wonder if it is possible to merge multiple rows from just one column in SQL. Here’s an example of my initial table: Here’s my expected output: I do not know if it’s possible to have a table like the later one. So, any advice would be much appreciated. Answer This type of task is usually do…
SQL Combining MAX and SUM
So I have one SQL table that contains the below columns: There are ~2800 unique License numbers and will have numerous FundsIn each day. I am trying to find the last date there was activity (ActivityDate) and the sum of all of the FundsIn on that MAX ActivityDate. Below is a query I’ve been trying to mo…
selecting max value from table with two variable colums (microsoft SQL)
i´m working with a table that looks like this: Start https://i.stack.imgur.com/uibc3.png My desired result would look like this: Result https://i.stack.imgur.com/v0sic.png So i´m triyng to select the max value from two “combined” colums. If the values are the same amount (Part C), the outcome does…
Postgres select * after groupby and max
Consider a table with an id PK and 26 columns. There is an index on (a,b) I’m trying to select the row where the unique pairing of (a,b) is most recent. IE what was the last record for each (a,b) Because ID is autoincrementing, know that the max is the last row. However, is there any way to have the
How to select one random id from the child table?
I am using 10.4.13-MariaDB. I have a parent table and a child table. Parent table (tasks) In interface it looks like And I have a child table (puzzles) – puzzles table – puzzles can belong only to child themes I want to get ONE random PUZZLE from EACH LEVEL. How to write a proper query? Expected r…
SQL find max date based on a non null other column
I have a table like so: And I would like to return an entire row containing the uniqueID, scandatetime, and latest scanfacilityname (i.e., max scandatetime where scanfacilityname is not null). I have tried the following query: But im not sure if this is correct/if I need the coalesce. Answer You can use the m…
Select every second record then determine earliest date
I have table that looks like the following I have to select every second record per PatientID that would give the following result (my last query returns this result) I then have to select the record with the oldest date which would be the following (this is the end result I want) What I have done so far: I h…