I have looked at similar questions previously but they seem to update a single column with multiple case conditions and the one answer I found for multiple columns seems a little long. Let’s say I have a table like this: Column_1 Column_2 Column_3 Column_4 Column_5 First Value 1 Second Value 2 …. …
Tag: sql
I want to update a string in a table
I have a table, content_history with a column, doc_filename, and each row has a string value. Each string has a | and the portion in front of the | is a filepath. I want to replace that portion of the string with the correct filepath if it doesn’t already match. What is the best way to go about doing th…
How to add a where clause and / or a order by to a update statement with declare
I am currently testing using the declare update statement below. This will update my StackCustomerAltID numericly from 1 thourgh 501. But I need to figure out how to add a where clause or a order by using my Customer column in asc order. here is the where clause I need to add (where DelFlg = 0 and Customer &l…
How to aggregate upvote and post tables together in postgres?
I’m looking for a way to aggregate posts and the upvotes related to that post together using PostgreSQL. I want to make it similar to reddit’s upvote systems, where upvotes come already fetched and don’t need to be loaded on client side. I have made these simple tables. upvotes.sql users.sql…
How to show pivot data without directly using pivot statement?
I am trying to pivoting the data without directly using the pivot function. I have a simple table t1 which has: My expected output is: I want to achieve this without using pivot. I tried using: How can I achieve the output without pivot? Answer You are sort of there, try the following: See Example Fiddle
How to list 3 largest numbers from table in SQL?
I’m trying to unite two bits of SQL codes and list three largest numbers from it. Here is table relation diagram Query #1: Query #2: My final code shows the full list of all first and second names, simply adding largest number to all of them from orders table. How can I modify it to make it show three n…
How can multiple unique in partition tabale?
I have a SQL table like below. I have a table. I need to unique order_no column with user_id column. there is no any problem. But I have to unique data_time column because of I use partition. but date_time column has to be separated with user_id and order_no. By the way I don’t want like this unique (us…
Calculate the time period a certain field is overlapping in SQL Server
I am currently trying to figure out the overlapping time period between records. I already have a query that indicates if it is overlapping another field with ‘yes’ and ‘no’. But I need to have the exact duration of the overlapping time period when the field has ‘yes’ as in…
on SQL can I have a ratio column based on a count of multiple parameters?
On this query here, I get the following result in the image provided below. However I want to take it a step further and turn the count into a ratio of wins / total wins. However when I use the second query (at the bottom) I get an error invalid use of the group function. To explain, the count is
MySQL- Find records with overlapping period
I have a table hotel_booking reference start_date numberOfDays ABC 11-08-2021 2 DEF 12-08-2021 2 GHI 13-08-2021 3 JKL 10-08-2021 2 So the first task I wanted was to get all bookings which has startDate between x and y date which is straight forward query This returns me ABC and DEF which is perfect. Now I wan…