Skip to content

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 &#8…

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…

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 …

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…

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…