Skip to content

SQL Server – current inventory with physical count

I feel as though I’m missing something extremely fundamental that should be obvious. I’m basically trying to take the below data and calculate a fifth column: Inventory_Current. Example data: DateStamp ProductID Inventory_Change Inventory_Count 2021-07-01 100 -300 100000 2021-07-01 200 -700 50000 …

Exploding the group by cel in individual cases

I am trying to convert the following table (fictitious): Person year price Tom 2019 100 Klaas 2020 100 John 2019 120 John 2020 120 Klaas 2020 150 Klaas 2020 150 John 2020 150 into: Person year price price price Tom 2019 100 NaN NaN Klaas 2020 100 150 150 John 2019 120 NaN NaN John 2020 120 150 NaN In

Name of customers who are of legal age (18 years) Postgresql

I have a question about how to return only customers over 18 years old. I’m just getting back from the customers Answer If you want to filter the rows, use a where clause. If you want to filter by age, you can use date comparisons: Note that phrasing the condition this way makes it friendlier to indexes…

Find floating-point numbers

I have a table Balance with a column Coins of double type in my MySql database. However, in fact, I store int values there. So, I want to change the type from double to int. But before, I want to be 100% sure that there are no floating-point numbers in this column. What kind of SQL request should I write

Postgres on Conflict Update With Default Column Expression

In case a column has a default value expression Is it possible for on conflict statement reset the column with the default expression without copy-paste the expression it self using default as a value while composing excluded record it self I.e. just to refer the default exactly from the update statement. Som…

SQL join to find relavant codes and address

Below table contain address information. Code Code1 Code2 Address DAN001 DAN004 DAN005 ABC, Newyork. DAN004 DAN004 DAN004 Delhi, India DAN005 DAN005 DAN005 Ever, Belgium Please find table details below: Each Code have associated code1 and code2 and address last column. for example: DAN001 is associated with D…

How to group by fields which have specific value in SQL?

I have the following columns in my table (I’m using postgresql): parent, child, status. Each parent has 1 or 2 children. I want to select all parents whose first child has status x and second child has status y or in case there’s only 1 child than parent with child with status x. For example, a ta…