Skip to content

Tag: sql

How to combine columns, group them then get a total count?

Below is a table that has candidate_id, two interviews they attended with the interviewer’s name, and results for each interview. candidate_id interview_1 interview_2 result_1 result_2 1 Interviewer_A Interviewer_B Pass Pass 2 Interviewer_C Interviewer_D Pass Reject I need help to combine column intervi…

MS SQL Server view with conditional values

I have a table A that can reference to itself to inherit some values from a parent. The reference is represented with ParentID. Parents have null values in ParentID. ID ParentID Field A Field B Field C 1 NULL ValueA1 ValueB1 ValueC1 2 NULL ValueA2 ValueB2 ValueC2 3 1 null ValueB3 null 4 1 null ValueB4 null 5 …

SQL query to get values by the calendar month

I have the following schema: and i want to get a return object that has the industry id along with the number of items but based on the calendar month for the previous two months, not including the current. So i want the number of items in October and the number in November. What i have, that is not working

Optimize nested inner joins

The following TypeORM generated SQL query takes over 11 sec to complete : Given the following database indexes : It feels like some left joins could be indexed, but I am unsure how to do it the proper way. Besides from indexing, is there anything I could do from TypeORM (or other), to really speed up the requ…

Is it possible to use a SELECT statement inside a CONCAT?

I’m trying to create a string from table values, along with some text to make it more readable. The only problem I’m having is that I can’t get the SELECT statement to work inside my CONCAT. It’s been bugging me for quite some time now, and I would appreciate any feedback on what I&#82…