I implemented a quicksort in Java and it works properly but i dont understand the second swap in the partition function?

private static int partition(int[] array,int links, int rechts) { int pivotelement = array[links]; //pivotelement on the left int i = links; // links means leftside int j = rechts; // rechts means rightside while (i <= j) { if (array[i] <= pivotelement) { i++; } else if (array[j] > pivotelement) { j–; } else {… Read More I implemented a quicksort in Java and it works properly but i dont understand the second swap in the partition function?

choose latest partition of a Bigquery table where filter over partition column is required

I have been using the following query SELECT DISTINCT * FROM `project.dataset.table` t WHERE DATE(_PARTITIONTIME) >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY) It is not ideal as the partition could be unavailable due to delay.. Thus I try the following queries SELECT DISTINCT * FROM `project.dataset.table` t WHERE DATE(_PARTITIONTIME) IN ( SELECT MAX(DATE(_PARTITIONTIME)) AS max_partition FROM `project.dataset.table`… Read More choose latest partition of a Bigquery table where filter over partition column is required

PostgreSQL: Count common values of column B between ids of column A

I would like to count the common friends between users. However, I’m struggling in coming with an approach as the users are in the same column. Imagine the following dummy tables: with users (user_id, user_name) as (values (7,’ Adam’), (5,’ Tom’), (35,’ Bob’), (72,’ Charlie’), (2,’ Maria’), (10,’ Isabel’) ), friendships (user_id, friend_id) as (… Read More PostgreSQL: Count common values of column B between ids of column A

ROW_NUMBER() OVER (PARTITION BY) gives same row numbers

I use SAP HANA database for a project. I tried this SQL query to get values with a row number. But it gives 1 as all rows. SELECT ROW_NUMBER() OVER (PARTITION BY "ItemCode") AS "ID", "ItemCode", "CommitedQty", "JobId", "WarehouseID" FROM (SELECT "ItemCode", SUM("CommitedQty") AS "CommitedQty","JobId", "WarehouseID" FROM "Stock" WHERE "BaseEntry" = 10352 GROUP BY "ItemCode","JobId",… Read More ROW_NUMBER() OVER (PARTITION BY) gives same row numbers

SQL sum of negative values until condition (positive value is seen) is met, then restart the summation

I would like to get the total of negative row values until there is a positive value (here column change in table below). After another negative value in the column, the sum should start accumulating the negative row values again until there is another positive value and so on. Given the following table: +─────+─────────+─────────────────────────+ |… Read More SQL sum of negative values until condition (positive value is seen) is met, then restart the summation

Find rows that have the same value and select the newer one

I got a table, that looks like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 4567 12EE56423 2018-06-12 6789 AD3FF0C44 2018-03-08 9101 AD3FF0C44 2019-06-07 From rows with the same sensorNr, I only want to select those with newer ModifyDate, so the result should look like this: serialNr sensorNr ModifyDate 1234 12EE56423 2022-04-06 9101 AD3FF0C44 2019-06-07 How… Read More Find rows that have the same value and select the newer one

check if record exists in previous date and not in current date in the same table and return count of records matched and unmatched

I am trying to get the count of records that were there in one date and also in another date. What would be the most efficient way? id date AB 6/11/2021 AB 6/11/2021 BC 6/04/2021 BC 6/04/2021 AB 6/04/2021 AB 6/04/2021 This should return True =2 (Ab is present in 04/21) and False=2 >Solution :… Read More check if record exists in previous date and not in current date in the same table and return count of records matched and unmatched