I’m using Postgres and I have the following schemes. Orders Comments So, in this case, an order can have many comments. I need to iterate over the orders and get something like this: I tried to use LEFT JOIN but it didn’t work it returns this: Answer You are almost there – you just need aggregation: I would strongly recommend
Tag: string
Stored procedure to unpivot
I have a table with these columns: Where fields from 01 to 50 are dates. I need to have a table like this: Where title code should be the column name from 01 to 50, data should be the value of that column in mytable I did this stored procedure by looking in older questions: but I’m getting a syntax
Depending on column value, query different tables
I have table A where each IDENTIFIER value is unique. Depending on whether its CC or DC, I need to join it with different tables, for example if its “CC_” I need to map it to table B and if its “DC_” I need to map it to table C. TABLE A: TABLE B: TABLE C: I want the result
Conditional Grouping in SQL
This should be easy, but I’m having trouble with it. I have a results table that looks like this: Notice that the pct column sums to 1.0 for each store. Here’s the code to create this table: I’m trying to group the results by store, then by cust_id while creating a new category A&B if the same cust_id has both
PostgreSQL Can’t Convert String to double precision
So I’m asked to do this query for a college project: SELECT l.city AS name, AVG((pr.ap_price::double precision * 7 – pr.weekly::double precision) …
How to search in a SQL database table
I have a table with the following columns: user_id user_name user_unit user_last_name user_first_name user_email I want to write a query that the user declares a string that contains a word/part of a word/user_name/user_id/full name/ext. and the query returns all rows the contains the string, sorted by most relevant. Any offers? Answer You can concatenate the columns together and use like:
How to get all the patterns from the column in Oracle Sql
Below is a text in a column: P348955: REMOVE NHA P210 PANEL PN : 6703ELM21 & REMOVE SUB ASSY PN: ELM2000-10-10 (ITEM 70) QTY 2EA & PN: ELM200-11-10 OR ALT (ITEM 75) QTY 1EA & PN ELM1057-1 QTY 1EA REQUESTED BY MMEECHAN REF ID 7369 I am looking to extract all similar patterns from that text, The pattern is defined
Single query to split out data of one column, into two columns, from the same table based on different criteria [SQL]
I have the following data in a table, this is a single column shown from a table that has multiple columns, but only data from this column needs to be pulled into two column output using a query: Required result: distinct values based on the first 13 characters of the data, split into two columns based on “long data”, and
How to get vowels in Like operator of SQL?
I was solving a problem on SQL from Hackerrank. I have to make a query such that it gives me all city names starting with a, e, i, o or u. I’m using Like operator but still wrong answer. Here’s the problem Link Here’s my solution- Can anybody explain? Answer LIKE does not support that parttern. You need a regular
Change date time format from YYY-MM-DD HH:MM:SS to YYYY.MM.DD HH:MM:SS in SQL Server
I have a table with a column RequestDate with following format 2019-12-01 00:00:00:000. I want to see results like this: 2019.12.01 00:00:00:000. I used this command From the above query I am seeing results as 2019.12.01, but I am missing time (00:00:00:000) – how can I keep along with time. I want final results like 2019.12.01 00:00:00:000 Answer I don’t