Skip to content

Tag: sql

HOW TO CHECK CONDITIONS FOR PREVIOUS MONTH

My table is like I am trying to get customer_ids where they didn’t do any transactions previous month and made transactions with at least 2 transaction_type at this_month.While doing this I am converting rundate to MM-YYYY format. What I’ve done for getting previous month and this month on MM-YYY …

Merge tables with unequal number of columns without returning duplicate rows

I have two tables, one is called original_table and the other is table_with_additional_column. table_with_additional_column is a subset of original_table but with an additional column called sequenceNr. I want to merge the two tables such that I can get all rows from original_table with sequenceNr set to NULL…

How to join a table with itself?

I want to ask how can I join the table with itself, using the same column twice, and giving each a different WHERE to sort out. I have an Employees table that contain Employee_name, job_id and manager_id. I want it to get the name of all the managers through the job_id on one column, and then all the employee…

SQL zero-to-many column comparison

Say I have two columns in a table, a and b. For each value of a, there can be zero-to-many values of b. If the columns are sorted by a, then by b, what is the most efficient way to mark the first value of b which is greater than the corresponding value of a in a new third column?