Skip to content

Creating a recursive query in SQL

I have data like this: Person A has a relationship with Person B, and person A has a relationship with Person C Person B has a relationship with D and E. I want to view result in group in SQL Server (A, B ,C,…) and (B,D,E,…) I have tried looking recursive but not getting this to implement. I need …

SQL query NOT EXIST very slow

I’m trying to optimize an SQL query as it is slow, and gets slower when the query result is high. There are indexes concerned fields and Tables are quite big. Answer As a starter, this condition: Should be rewritten as: This is functionally equivalent, and not using date functions on the column being fi…

Correct way to get data for BIRT reporting

We have a system which contains 4 Hierarchies. 1. Senior Manager 2. Manager 3. Supervisor 4. Employee Data related to all these are stored in different tables with respective details. There is a single address table which contains address of all these hierarchies. Sample Data Set We would be able to do a coun…

Subquery to check date availability

Could you help me with finding a solution to my query problem? I am stuck with it already for a week so I decided to try to ask for help and learn something. I am using MySQL database. Right now I have a table without the “search feature”. This is the result: I want to show all rooms in the

Value from 2nd Row of column copied to 1st row of next column

The table looks like below. I am trying to make 1 new column say SuprerFrez whose value is depends on column FREQHZ. For every UVRID group 2nd value FREQHZ will be 1st value of SuprerFrez and for last FREQHZ, SuprerFrez value will be zero. Expected output with 1 new column whose value depends upon FREQHZ colu…

How to sum and count in grouping in sql

I have tables like below. I would like to grouping and counting by referreing to its score. First, I would like to sum score by customer It achived by group by method. second, I would like to count by binning following band. I couldn’t figure out how to count after grouping Are there any way to achieve …