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 rounding is applied when casting, as
Tag: select
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 follows: Thanks 🙂 Answer Just another option is to
Query to get all companies that have products with all specified attributes
Let’s say I have two tables (1 to many): table company with fk id and table product with fk id and also fields sId and tId (if sId has data tId is null and vice versa, not sure if it matters). I want …
Remove specific fields and show other fields in Mysql
I would like to ask for ways to solve this MySQL issue. Currently, I have this select query SELECT username, friend_username from friends WHERE (username = “apple” or friend_username = “apple”); …
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 achieve this? First table looks like
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 the current Output and the
Create a View in SQL with a Concatenated Column > Then use Case Statement to affect values
I created a view with a concatenated column named DisplayName, using the code below. Is there a way to change specific DisplayName values using a case statement (or a better method) Something like: case when DisplayName = ‘Robert Jones’ THEN ‘Bob Jones’ when DisplayName = ‘Thomas Simms’ THEN ‘Tommy Simms’ or when FirstName = ‘Robert’ AND LastName = ‘Jones’ THEN
T-SQL – adding more date values to a table all rows
I have a table that contains many IDs as random numbers and I would like to create another table that contains all the IDs with another column having dates from first day of the year until a specific date. For example: My actual table looks like: And I would like to have a table if my specific end date is
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 in the adjustments table: Was it
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 – if data exists but not distributed to employee