Skip to content

Using Case Statements As a Pivot – DB2 SQL

I want a list of motor carriers, with trailer equipment counts listed in separate columns. I am using case statements to categorize the different equipment types, but I’m getting multiple returns …

select distinct window function in PostgreSQL

I have a data table like the following: How do you select the distinct continuities for each Longitudinal distance in a 10-step rolling window? Ideally, I’d want something in the Ideal output column …

Dividing by decimal values – rounding issue

I’m trying to divide two decimal values, in hope they will return the following; 1.132930. However, SQL appears to be rounding the value to 1.132931. The value returned before conversion is 1.1329305135951. The SQL code i’m using is as follows: Answer You can round the value before the cast as fol…

EXISTS not working with subquery in WITH clause

I ran into a query where the EXISTS clause is not working properly. The query returns results even for items where no matching record exist, seemingly ignoring the EXISTS completely. It used to work …

SQL Combining two different tables

(P.S. I am still learning SQL and you can consider me a newbie) I have 2 sample tables as follows: Table 1 |Profile_ID| |Img_Path| Table 2 |Profile_ID| |UName| |Default_Title| My scenario is,…