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: …
Tag: sql
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̵…
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
Scalable method to union all column in a table – Big query
Let’s say I have col1 col2 a c b d and I want to have only one column, I’d do and get col1 a b c d But now let’s say I have 100 columns (all strings, same data type), what’s the best way to add all the columns together without doing a union all for all the columns? I
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…
How to pull rows from a SQL table until quotas for multiple columns are met?
I’ve been able to find a few examples of questions similar to this one, but most only involve a single column being checked. SQL Select until Quantity Met Select rows until condition met I have a large table representing facilities, with columns for each type of resource available and the number of thos…
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…