suppose we have the following masterdata: and we have the order tables: what is requested is to have one single query that could return 2 different sets of data, according to the value of a given variable v_order_status: v_order_status = ‘del’ then only transport orders is retrieved: v_order_statu…
Tag: sql
Why do I need to declare variables twice: within and without the dynamic query?
I’m reworking an existing static query to be dynamic. Why am I needing to declare the variables twice? Once at the top of the file (for a subsequent, unchanging query) and again within the dynamic …
how to combine multiple rows into one row?
My table: What i want to get is: Is there any simple way for this? Answer If you are using MySQL 8+, then ROW_NUMBER combined with pivoting logic provides one way:
Combining MAX and SUM in an Oracle ROLLUP
Here’s my SQL: The output looks like this: I was expecting it to look like this: In other words, I was expecting the rollup to sum up the maximum weights of each food instead of taking the maximum of all the maximums in the food-type category. I do have a solution of sorts, but it means having to add an
SQL connection string is not recognised and throws and exception in C#
CONTEXT: I am writing a WPF app. It works with a SQL Server database in which I put some data, concretely the strings Titulo and Descripcion, the int XP and the string fotoMision. When I click a …
Add Sequential Letter column to table
In C I can switch between int and char to build a list of sequential integers and then convert them to ASCII characters that will be sequential according to the alphabet. Is there a way to do this in …
Query to modify where clause to specify relation
I have 2 tables: users & user_roles users: id name 1 John 2 Doe user_roles: user_id role 1 admin 1 finance 1 accounting 2 admin 2 finance 2 admin I want to get the users that have admin & finance roles in the output(with distinct). So the result will be only user with ID of 2 (Doe) What is the
postgres – aggregate items in text array
I have an array of text items, each text item in the array is a delimited string, here is a sample: drop table if exists tmp; create table tmp(x text); insert into tmp select (‘1~41.5~50~1|2~43.72~…
Find sum() from two different tables and join them based on a condition?
I have two tables, Table1: ID Amount Date —————— 123 500.00 02-Sep-2020 123 240.00 02-Sep-2020 124 200.50 02-Sep-2020 125 150.70 03-Sep-2020 123 480.80 03-Sep-2020 Table2 ID …
Oracle SQL: how to show only one max per group
Hi everyone first thanks for your time. I have this data Data: And I have to obtain the max values of everygroup, if there is one group that has two same max values like A 40 23/56/1982 A 40 31/4/…