Skip to content

Tag: sql

count business days in calculation

Continuing from my previous question: case when date column is greater than sysdate then ‘Y’ One thing I forgot to consider was including working days in the calculation. Here is the query: So I need to exclude Saturday and Sunday in the calculation above. I tried to add this in the where clause: …

find the max for each value in SQL

i have tables like this table 1 table 2 i want to get the max value for each element in table1 from table2 and the different parameter so the expecited tabel should be like this Answer You can try to compute all the maximums: and then join them with the original Table2, e.g.

Selecting the maximum date before a certain year

I have a table where I’d like to select only the record with the maximum date: The issue is that I have some IDs in the table where the maximum date is in 2022, so that is what gets selected. How do I select the maximum date for a record that is before 01JAN2022 so that my output look like

Before/After Difference for a flexible Date (Case)

i have a little problem with a case. I output two date fields (yyyy-mm-dd). the date changes and is flexible. not every entry has the same date fields. I take one date field as an fixed point. If the Date is 4 months before the date, a ‘V’ should be the output. if it is behind it, an ‘N&#821…

Validation trigger not working in SQL Server

I am working on a trigger for a class project. I have a table named salesman with a column named type. All employees in the table currently have a type of full, part or temp. The purpose of the trigger is to check a newly inserted row’s type and make sure that it matches one of the three that already

Handle pg_error on generated columns

I have a table that consists of some PostGIS related data. These data are generated automatically on INSERT or UPDATE. Sometimes the data provided on the polygon column might not fit the generation function and cause an error. I wanted to handle this error and set a default value when it fail. — Last re…

MySQL self join but in the same row

I have this table: date sku note 11/12 123 note 11/13 123 note 11/12 456 note 11/13 456 note 11/12 789 note 11/13 789 note (Note is random) And I want the result to return this: date sku note sku note sku note 11/12 123 note 456 note 789 note 11/13 123 note 456 note 789 note I tried self

postgresql combine 2 select from 2 different tables

Hello i need to run a query with 2 select statements, one with an avg calculation and grouped by name and the other select, looking for that name in other table, and get some columns and do a JOIN to merge both and only left one column “name” on it. The first table its this: The second table its l…