Please see code below. For every Underwriter that exists that is in a given month, I need every single date in the month and the given Underwriter. Thank you so much Original Table: Desired Output: Please note that Rebecca should not have dates for 12/1/2019 to 12/31/2019 Attempted Code Answer Use a Tally, th…
Tag: sql
SQL statement to update rows in a table, insert into/update same table
I have a seemingly pretty simple situation here, but one which I have never dealt with. I have researched the issue and have found situations pretty similar, but not close enough to run on a production db. I have 1 table with 2 columns. I want to find all entries that share the same values in column 1, and up…
SQL Query to find duplicates in one table but only if at least one of the duplicates has an appointment which is in a different table
Thanks to this great community I’ve already had a huge success in my data searching. Using: It listed out all my duplicate values! Now, I’d like to take this a step farther so that I can list ONLY those duplicates that have an appointment on a certain day. There are several issues I’m runnin…
SQL : Only one expression can be specified in the select list when the subquery is not introduced with EXISTS
I tried query like this but i got message like Only one expression can be specified in the select list when the subquery is not introduced with EXISTS Code: Answer I guess you need below –
Show specific rows in SQL by not existing in another table
I’m not very experienced in advanced SQL and stackoverflow, so I’m trying my best to explain what I need. Let’s say I have a table called ‘Shift’ and a table called ‘Schedule’. ‘Shift’ has columns ‘shift_id, shift_start, shift_end, shift_day, shift_f…
Find between which 2 numbers a value lies in MySQL
I have a variable @k=35. and a table xrf having contents as show below. How to I get the values in between which @k exist in table xrf. output is 30 and 40. Answer Using conditional aggregation
How to combine two queries with case statement
How to combine two queries with case statement query1 query2 Expected output: Answer With conditional aggregation: The conditions where by_user = ‘3’ or where by_user <> ‘3’ are checked with a CASE expression, so they are removed from the WHERE clause.
Seperate tables with same attributes in SQL
When using SQL database, when I have tables with same attributes. For example if I have [posts] with attributes (id, image, description, number of likes and dislikes) [Comments] with attributes (id, image, description, number of likes and dislikes) and [Replies] with attributes (id, image, description, number…
How to group by multiple rows and column
For each user 3 codes are there(10,20,30) if all codes(10,20,30) are true then it has to JOINED if any codes(10,20,30) are False then it has to NEGLECTED WE have to check max(date) Table is below: Output user2 and user3 is JOINED, user1 is NEGLECTED Answer I assume that the column bool is of data type BOOL, s…
How to break a row into multiple rows based on a column value in Athena (Presto)?
I have a Athena table that has a column containing array of values. I want to create multiple rows from one row such that the column of array can be changed to contain only 1 value. E.g. : to look like : How can I write my query to achieve this? Answer I think unnest() does what you want: