I have a table with date type column. I am trying to insert date in it: But I get an error: Please give me to make the correct query to put the date Answer Easy fix::
Is there an idiom for querying sequences in SQL?
I’m studying to interview for a job involving a lot of SQL. I’ve noticed a few exercises that revolve around returning values based on a sequence across rows, and I would love to know if there’s a standard way of doing this. Something akin to the subquery below I’ve found useful for se…
postgresql how to choose specific column from exact same columns?
I have table A and B. If I inner join them like SELECT * FROM A INNER JOIN B on A.a = B.a The new table has two exactly the same columns “a”. How do I choose the first column of “a&…
SQL – How can I rewrite this request without many SELECT
I want to have the number of open requests for each month before the 1st of each month. I use ComboChart and my orange line is, at the moment, the average for the 6 past months, I want to change this data for the opened requests. Exemple : for April, I have 2 new requests and 1 closed request and
Populating Bridge tables
Hello I have a bridge table that has these two columns only to carry the IDs from other dim tables I’m wondering how can I populate this bridge table and make it related because a simple insert into a …
SQL: select 3 values and count how many times they are different
Say that you need to query some data and that there are three fields like the following (this is part of a larger query): Field1, Field2, Field3. So you select them like this: I need to compare these values and return the variable Result that is computed as follows: 0 if they are all the same 1/2 if two are
NULL Values at Bottom of SQL Table – SQL Server 2000
I have a table with information containing names and emails. I have to put the rows containing NULL email values at the bottom of the table, but am unable to when I use the SELECT DISTINCT clause. …
SQL – return rows in partition based on max value
I have below dataset with comments which row must be returned. Logic is: return value for max kg_to within partition of each country. Current working code: Question: Shorter code would be better, any ideas on how to improve it? Answer Use distinct on: Or window functions: Note: I also don’t see how your…
PostgreSQL group by column with aggregate
I need to group by id and select the task with min/max seq as start and end But this results in But I do not want group by seq Answer One method uses arrays: Another method uses window functions with SELECT DISTINCT:
TSQL PIVOT/UNPIVOT Multiple Summarized Columns
Seems this is a popular topic but I can’t seem to replicate other answers. I have data that is already summarized by month/year for multiple categories. What I’m trying to get is this Here’s the query to provide the data I’ve used PIVOT a bunch of times, but with a single “catego…