I have two tables: g_relationships (id,request_id,receiver_id,status,approved) g_users (which contains: id,username,…) I have a hard time making a query that adds a temporary column, checks whether userid: 4 exists in request_id or receiver_id column, and take the other userid and fetch username from g_…
SQL Case statement with Count?
I have a database that allows for more than one ethnicity per person. Unfortunately, our answers are essentially Yes Hispanic, Not Hispanic, and Unknown, and there are some who do indeed have multiple selections. I need to run a large query that pulls lots of info, one of which is ethnicity, and I want to …
dynamic pivot SQL Query in DB2
I have table like below in DB2 where all these 3 columns are VARCHAR data type I need a dynamic PIVOT query which should select values for ABC_COL1 and ABC_COL2 in row format when FILE_NM filter is used as ABC.TXT The same query should select the values for XYZ_COL1, XYZ_COL2 and XYZ_COL3 in row format when F…
SSRS Converting MultiValue Text Paramater into a String in SQL Syntax
I am being forced to use an ODBC source for SSRS report builder, source is Impala SQL, which doesn’t support the use of parameters. So I had to use a string builder function to get parameters into my script. This is working well, however the ask was to allow for multiple values in the text parameter. I …
How to write a SQL to count total number of occurrences of value in column after group by while taking count as 1 if the group has the value?
I have a data with following structure As title suggests, I want to count occurrence of ‘FAIL’ in ColumnC after grouping by ColumnA, and ColumnB and while counting the occurrence, I want to count only one ‘FAIL’ in the group. For example, if I did the counting for the above example dat…
splitting strings in sql
I have a table with 2 columns, one for id and one for country. I’ve found some rows in the table where it looks like the below: ID Country 1 US and Canada 2 France and UK How can I write a query …
How to check if a node is repeated in a ltree – PostgreSQL
How to check if a node is repeated (exits more than one) in a ltree? Something like this: ‘0.1.2.3.4.3.9’ ==> True ‘0.1.2.3.4.5.9’ ==> False
Getting row samples from PostgreSQL
I have a data table with timestamp and some data columns. The rows are inserted in arbitrary time intervals, i.e. the timestamp difference of consecutive rows is not stable but ranges from several seconds to several hours. I need to select one row per time interval of constant length, if there is any. Example…
REGEXP_SUBSTR – How to return value between ‘ ‘?
I need to return values from ‘ ‘ from below string (eg. for psOrderByClause I need value xxx_seqno). Additionally I’ve also need to return TRUE/FALSE values for some variables – there is no single …
Display all data which are between these dates
So currently, I am trying to display a list of items which are not between date X and date Y. Let us assume that book_date_start = 2021-06-15, and bookdate_end = 2021-06-20 This is my current query: So based on this So basically as I was writing the above out, I realized that my query is WRONG, and since 2021…