Skip to content

Tag: distinct

Get distinct values within time chunks

I have a table with different species and their occurences (timestamp) from field survey: Now I want to count them, not in total but in chunks of 10 minutes each, where only the first occurence is counted. That means between 12:31 and 12:40 there are species A,B,C. Between 12:41 and 12:50 there are species B,C. For a single 10 minute

SQL query to fetch distinct values from same table

Let’s say I have this table: employeetable: empid joindate location HRupdatedate Changes 1 2002-01-05 Delhi 2021-03-01 New 2 2009-09-09 Mumbai 2021-03-05 New 1 2010-06-27 Hyderabad 2021-03-03 Transfer 2 2015-11-02 Delhi 2021-03-06 Transfer 3 2020-01-01 Mumbai 2021-03-06 New 4 2007-07-30 Delhi 2021-03-04 New I want to get data from this table where empid in (1,2,4). That will return: empid joindate location

Select Last Rows with Distinct Field

I have a table with the following schema: In this table only the id field is unique. I’m concerned with getting the rows containing the last X distinct itemid, ordered by date. For example, in the sample above, if I’d like to get the last 3 distinct itemid, I’d be getting the first 4 rows, since in the first 4