This is my statement for the final course grade for all those students taking MATH, how can I adjust this so it displays the final course grade for MATH, but only for students who are taking both MATH and ART ? Answer You can do it with conditional aggregation: First, you should use a proper join with an ON c…
Tag: sql
Output array type column
I have a table like so – How do I output this result – Answer For an array, you would use array_agg(): If you want the value as a comma-sseparated string:
mySQL update average amount of last 5 dates when there is gap in dates
I have mySQL table like below, Is there any way I could update the value in table2 to where ? is placed. need the last 5 Days Average Amount when the sales actually registered, from last 5 dates from table-1 for(9th, 7th, 3rd, 30th, 28th) Answer here is one way: to update :
How to iteratively use INSERT INTO in PostgreSQL
I have Table1 with rows I want to iterate over, and insert values from those rows of data into another table. So basically pseudo is: Just looping through Table1, adding in one of its values every time. Answer I think you just want an INSERT INTO … SELECT here: Most SQL operations are inherently set bas…
Get all ancestors of a child in postgres recursive query
I am trying to get all related ancestors of a child with more info by joining with another table. I’m kind of new to backend so recursive cte is hard to understand. Find SQL Fiddle here Data I have : product_id,user_id Data I need : user_id master_id cost id(john_snow) null 4 id(bran_stark) id(john_snow…
PLS00215: String length constraints must be in range (1..32767)
I am new to pl/sql. I want to create a procedure that has three parameters called ‘startMonth’, ‘endMonth’, ‘thirdMonth’. In the procedure, I am executing a sql query which is in ‘run_sql’ column in table_query. Values for ‘startMonth’, ‘endMon…
Search Algorithm Implementation using NodeJS + MongoDB(or SQL)
There is an application with search input that gives an opportunity to search for contacts by their information stored in database. For example, I can type 0972133122 Alan and my search engine must return all contacts whose firstname is Alan & whose numbers match 0972133122 string. Of course, I can just t…
How to determine the order of the result from my postgres query?
I have the following query: This is giving me the result: Sometimes the order changes of the result changes from SOH -> SOC or from SOC -> SOH. I’m trying to modify my query so I always get SOH first and than SOC.. How can I achieve this? Answer You have two times that are identical. The order by …
SQL logic to fail a check if any of the related customers has failed
I have the requirement to flag the customers Y only when all the related customers have also passed the check. below are the two tables: relationship table : Check table I want output like below: output justification: since 1,2,3 are related customers and since one of them (3) has n in table 2 , so all the re…
Updating multiple rows for user – Setting 1 row as “Default” Yes, and other to be No
Lets assume the following data selected from SQL TBL_Profiles: No User Profile Default 1 User1 Profile1 Yes 2 User1 Profile2 No 3 User1 Profile3 No Currently, User1 default profile is Profile1. That’s how it was setup initially when profiles were created. If User1 decided at a later stage to change his/…