Product table Size table Query: Current output: Expected output Note: Due to current query I’m getting 2 record for the same product and my limit and offset query logic is getting false and not getting proper count. I’m not well aware of Postgres queries for this kind of situation. So I need solut…
Tag: sql
Mysql TRIM/RTRIM/REPLACE doesn’t work to remove trailing spaces from an email column
I have this insert select statement, copying data from employee bulk add staging to employee table: Even if I change it to RTRIM or REPLACE(eb.tr_email, ‘ ‘, ”) to replace the spaces with nothing it will still not modify the data to be inserted. I cannot get my login to work since my backend…
SQL – Flag rows till 0 value of each group
I am calculating a running balance and want to flag all rows till 0 value to have ‘MATCHED’ flag else ‘NOT-MATCHED’ flag with respect to account ID. Here is what I have tried but didn’t got proper result: Answer We can use a sub-query to find the last acct_rank which is 0 and the…
sql – select partially unique values and concatenate non unique values into string
Say I have the following data set: How can I group by columns A and B and return a third column that is all unique values of C for that group concatenated together (in a comma separated string) using SQL. For clarity this is the resultant data set I am looking for: I am currently querying this in MS access,
How to add additional XML node on top of my SQL generated XML
I have generated XML from a SQL Server FOR XML PATH statement as shown here: And this is the result: Now, I’d like to encapsulate the above with these nodes: How will I achieve this in a SQL Query I created above? I am new to SQL Server and XML. I am trying to generate this XML directly from my
Split strings in a column based on text values and numerical values such as patindex
I have a column that displays stock market options data like below: I want to be able to split these up so they show up like: I was able to split the first portion with the ticker name by using the code below, but I don’t know how to split the rest of the strings. edit: for anyone who is
How should I use `json field` in where clause in postgresql?
I have a json field in postgresql table feeAmount: I’d like to query rows whose feeAmount -> value is not null. Some rows may be null for the entire feeAmount field. some rows’ feeAmount has a json data whose value is null. They need to be excluded. I have tried this query: but both of the quer…
SQL Optimization, Nested Query on the same table
i have to create a query that return employees having mutliple territories parent for the same function code : Table employee_territory_function Table territory the result must be the employee_id 12346 which have multiple parents my query was : The query takes much time execution with 10k for the couple ( emp…
How to concat columns into a string in Snowflake?
I have this table Movie with columns defined as (CustomerId, MovieId, Name) and I want to fetch these columns by concatenating them into a string in the position they are defined in Snowflake, by ordering through ORDINAL_POSITION. So I found that using LISTAGG() get’s me pretty close to what I want. By …
SQL Server – Counting total number of days user had active contracts
I want to count the number of days while user had active contract based on table with start and end dates for each service contract. I want to count the time of any activity, no matter if the customer had 1 or 5 contracts active at same time. In result I want a table: Where 1477 stands by 1053 (days