I currently have two tables with the following data: I currently have my query set up like this with Knex: I’m currently parsing the data into the following format: This works totally fine except for the cases where the parent has no children, as it won’t pull any data at all, including parent inf…
How do I return NULL conditionally from a JSON_QUERY
How do I return a JSON_QUERY that returns NULL (or no property at all) if the selected value from the sub-query (or left join) is empty? Here is a simple example (imagine NULL below is a sub-query): This returns and empty JSON object – which is not what I want: Since NULL is being returned from the sub-…
Select from cross tables in postgres problem
Lets imagine i have a table A that contains rows X,Y and Z, and i have another table that relate elements from A to another table B. A_B : element_A, element_B, and i want a query that for element b in B returns for all elements a in A return True if {a, b} exist in the table A_B and
MYSQL no duplicate of 2 values
I couldn’t find an answer for this exact question although I am sure the information is on here somewhere. I have a python script that is adding stock data into a database. For each stock database has ~1000 lines where ‘ticker’ is the stock name and ‘time’ is the date(1 for each …
Logic for backward updation based on parent value
I have below tables with data as below Table_Cell Table_column Table_row I need to update SwitchCol in Table_column and Switchrow in Table_row Logic is If for an column_id in Table_column, all the combination with row_id in Table_row,present in table Table_Cell is 1, then make the SwitchCol =1 for that column…
SQL: How to select two employeeid within same team and have a team_score greater than 400 ? Mentioned the table schema below
Previous_teams id (integer) name (text) team_score (real) Team_members team_id (integer) employee_id (integer) employee_name (text) birthday (text) popularity (real) Q: How do I select a pair of employee ids that have worked in at least 5 prior teams where the (average)team_score was greater than 400 and coun…
Return multiple records, but it should limit 1 record per each similar condition
Expected results: Explanation: In the results, James is representing all people aged 20. And Blue is representing all people aged 15. And so on.. Question: How can this query type of query be achieved? Thank you. Answer If you want one name per age, you can use: If you want the first row, then:
Calculate sum of price from 2 table sql server
After asking about calculate the sum of the total price here and Its work but then went I add(SUM(PRICE*AMOUNT) AS TOTAL_PRICE) to create my own View, the Total_price = Expr1, It just PRICE * AMOUNT, there is no sum here. I apply It to create a view here is the query Here is the output Could anyone help me ou…
Best practice for verifying correctness of data in MS SQL
We have multiple tables with different data (for example masses, heights, widths, …) that needs to be verified by employees. To keep track of already verified data, we are thinking about designing a following table: This table links the different product id’s, tables and columns that will be verif…
SQL Query to display dates weekly from current date
I have a requirement to display dates every week starting from current date for 48 months. I was wondering if it is possible through SQL or i will have to write a function to achieve it. Below is my …