I found the single insert answer from this question: How can I insert values into a table, using a subquery with more than one result?. However, I’m looking for a way to do multiple inserts in this fashion. Single-Insert version WORKING! (using the previous answer…): Multi-Insert version (Failing) Is there a method of doing these multiple inserts of multi-column subqueries
Tag: subquery
Group rows by dense_rank() and loop through each sub-group and compare another column in next row of that sub group?
I have tried the following in LINQPad: I want to write a query which will return only the IDs 1 and 2 (not 3 and 4) because: ID 1 – has more than 1 rows and startdate of its rownum 2 is 1 day ahead of enddate of its rownum 1 ID 2 – has more than 1 rows and
get sum of all rows with id from main query
I need the sum of all positions from one year for every customer. In the subquery i’ve hardcoded the customernumber (mark 1) but it needs to be another customernumber for every row. The values in mark 2 are wrong. Thanks for your help! Answer If BAS_Customers and BAS_Contacts have a one-to-one relationship, then you should be able to use something
Create group column with values based on join [closed]
I have two tables 1) a customer table 2)Account table. I want to see what accounts are primary and which are secondary accounts. In one table I have accountRowId and AccountNumber. In the other …
MySQL – Joins and Subqueries [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 2 years ago. Improve this question I’m looking a question that asks ‘List for each year the name of
How to Find Unique Rows without GroupBy, Distinct
I have a SQL field that I only want to appear in a field in my sql query results depending on the value of FamilyType. So when the Family Type is 3B then I want FamilyID to appear. I do not want to have duplicate rows (without using distinct or group by or where clause = 3B). These are my
sql – Get the Minimum Value of 2 subqueries
I have a query which has 5 subqueries. I need it to have only 4 subqueries, since two of them are supposed to be only one result. The problem is I don’t know how to maintain the query structure and …
MySql last record from group by item_id with order by date
My database table name is ledgers and fields are id, item_id, date, …other fields I Want the last record from (groupBy item_id order by date ASC). from each group. I tried below query Can you guys please help. Answer You can filter with a correlated subquery: For performance, consider an index on (item_id, date). Another option is to use rank()
Solving Query-Errors in Vertica [Vertica][VJDBC](4160) and [Vertica][VJDBC](4680)
I have some issues in getting my Vertica query to work correctly. Let’s assume I have a relation which is defined as follows: CREATE TABLE KOMM ( MANDT VARCHAR(3), DOCNUM …
How to select MAX from AVG?
I’m practicing for my SQL exam and I can’t figure out the following question: “Of the average amount paid per customer, show the highest amount.” So to retrieve the average amount paid, I would do the following: Then I would like to retrieve the highest average amount out of this list of averages. I thought the following would do the