Skip to content

Tag: select

Redshift casting decimal to decimal

Why does casting a decimal to decimal lose all decimals? For example, Returns 2 Answer A decimal number has a precision (the total number of significant digits in the whole number) and a scale (the number of decimal digits). In Redshift, the default precision is 18, but the default scale is 0, and automatic r…

Converting month name to month number in SQL Server

I have a column (says Period_name ) that accepts varchar value. Inside the column, I have inputs likeJan-19, Feb-19, etc. I need an SQL instruction whenever left of Period_name comes like Jan, Feb then it should convert into corresponding month number. For example Input Output The SQL query condition is as fo…

Which join or approach to use

I have two tables. First table contains names of individual teams and teamID which is PK. Second table contains details about matches: homeTeamID, awayTeamID, result. I somehow need to combine these two tables in which I would have names (not IDs) of home and away team and the result of a match. How to achiev…

Difficulty filtering by Select Column

I’m going to apologize in advance. I basically stumble through SQL as projects need done but my knowledge is rather lacking, so I apologize for any incorrect terminology or poor syntax. I would appreciate it if anyone would be able to help me out. I have the following query. I have also attached pics of…

Simple Postgres query returning no result

I have two tables: and I have indexes on id in both tables, and an index on website_id and product_id on the adjustments table. This query returns data but it takes some 5 seconds with some 1k products and a couple hundred in adjustments: This other query however returns no results when there’s nothing …

Constant field has to be set MySQL

Attribute ‘Territory program’ is a constant field and has to be set to ‘Territory and Quota Program’ constant in result set, I don’t want to add a new column in table, so how can I do that in my select statement if possible? Also I have a column Status… not distributed &#82…