Skip to content

Creating date segments in redshift SQL

I’m trying to create segments of date based on a flag. Below is the table I currently have order by start_date,end_date. ID start_date end_date flag 9659 5/18/2012 5/18/2012 0 9659 5/18/2012 5/18/2012 0 9659 6/8/2012 6/8/2012 0 9659 6/8/2012 6/8/2012 0 9659 8/25/2012 8/25/2012 1 9659 8/27/2012 8/27/2012…

Return column name of max value in a row SQL Server

Initial Table: Output Table: I need to get the Job Name (column name) of the row with the max value in SQL Server. Is there a way other than else if to do this because ‘greatest’ function is not available in SQL? (Coz I have 50 Jobs at least) Answer You can use apply and window functions: That sai…

Difference between performing INSERT INTO vs Using MERGE INTO

I started working on a project that already has some scripts running and while I was looking some of the scripts that have already been done I encountered an scenario that looks something like this. My Question here is why they would use the merge into and force the mismatch just to perform an insert, they co…

count and sum in case statement

What is the difference below if I use case instead of sum? I believe I would get the same output? Thanks! Answer The three are equivalent. All of them count the number of rows that meet the particular condition (salary > 100000). All return 0/1 and would not return NULL values for the column. From a perfor…

shopping cart with PHP and connected to the MySQL

Good evening, I am currently working on the implementation of a shopping cart through PHP and MySQL, I am getting the following error at line 172 onwards, I have been looking at the quotes but I cannot find the problem, what could be the solution to this? I have been changing this cart from a mysqli version o…

Join two tables bring mismatch values MYSQL

I have two tables with >4million records i need to make a select query with where two columns match bring both tables value on this match and then i will insert that into a 3rth table: This is table A: (bitfinex) This is table B: (Kraken) I need to do a SELECT where timestamp and exchange_pair matches, as …