These are my two tables, wish do a mysql query to return: id_order,qty,id_user as name1 and updatedby as name2. I’ve tried this query but not working: Answer Use this. See the demo here: DB-Fiddle
Tag: sql
Show all varchar values with PIVOT
I need to show all varchar values with pivot but I’m not sure if that is possible? I have OCCUPATIONS table: Pivot query: Query result: Above query gives only 1 record in each column but I want to get all. Answer You ‘ll need an extra column, e.g. with ROW_NUMBER():
Count distinct per fiscal year and display all dates in query result
DB-Fiddle: CREATE TABLE customers ( id int auto_increment primary key, order_date DATE, customerID VARCHAR(255) ); INSERT INTO customers (order_date, customerID ) VALUES (“2020-01-…
SQL GROUP BY and kind of rereduce afterwards
I’m using PostgreSQL v.11. I have a table with 3 columns. My goal is to find redundancy inside data. First of all, I do a simple GROUP BY: SELECT client, block, “date” FROM lines GROUP BY …
Group by column and multiple Rows into One Row multiple columns
Please help me this: I want to group by column TestType, but Result should be splitted into colunms if they have same TestType I want SQL to return data in this format Result# column should be dynamic because each TestType has many Results Answer As I mention in the comments, what you need here is a PIVOT or …
Postgres – calculate total working hours based on IN and OUT entry
I have the below tables: 1) My Company table id | c_name | c_code | status —-+————+———-+——– 1 | AAAAAAAAAA | AA1234 | Active 2) My User table id | c_id | …
SQL Pivot count incomplete and complete
First of let me start by saying that my SQL know how is pretty limited. So I have below table Now I would like to create a pivot in SQL that looks like so Now PN from second column can repeat from …
Import and display a jpeg from a SQL Server database using r
Work has asked us to import a series of jpeg files from a SQL Server database for display on a dashboard product we have. We are using R to query our db and build our dashboards so we need to be able …
SQL Server – Aggregate data by minute over multiple days
Context I’m using Microsoft SQL Server 2016. There is a database table “Raw_data”, that contains the status of a machine, together with it’s starting time. There are several machines and …
Efficient way to ignore whitespace in DB2?
I am running queries in a large IBM DB2 database table (let’s call it T) and have found that the cells for column Identifier tend to be padded not just on the margins, but in between as well, as in: ‘ ID1 ID2 ‘. I do not have rights to update this DB, nor would I, given a number of