I need to create a custom quarter calculator to start always from previous month no matter month, year we are at and count back to get quarter. Previous year wuarters are to be numbered 5, 6 etc So the goal is to move quarter grouping one month back. Assume we run query on December 11th, result should be: YEAR MNTH
Tag: date
SQL query to select previous 14 months where add amount ‘0’ if any month is missing
I have create this query to select the date, amount for previous 14 months, In this case the month is missing if no record is present for that month, Please suggest me a solution to add zero and month …
Setting SQL variables for First day of month and 1 year before
Possibly a dumb question because I’m totally new to SQL (I mean never touched it before today ????) but I’m adjusting a report in a program we use, so it always gets values for the year ending last …
format date in oracle SQL
I was trying to learn how to format date in oracle pl oracle, when I ran below query its returns error Answer for my scenario I had to use to_char which perfectly solve the formatting issue.
How to compare a value within a range, inside (case when ~~ end as) query for mysql?
this is what I got: and I want to change this part as, for now I get the raw data of rssi, for example any digits between 0 and 120.. but now I want to change the rssi result if the data is in between certain range. For example, if rssi is between 0 and 20, its 1. if its
MySql last record from group by item_id with order by date
My database table name is ledgers and fields are id, item_id, date, …other fields I Want the last record from (groupBy item_id order by date ASC). from each group. I tried below query Can you guys please help. Answer You can filter with a correlated subquery: For performance, consider an index on (item_id, date). Another option is to use rank()
Getting date, and count of unique customers when first order was placed
I have a table called orders that looks like this: And that contains the following data: I would like a result set returning each unique date, and a separate column showing how many customers that placed their first order that day. I’m having problems with querying this the right way, especially when the data consists of multiple orders the same
Selecting columns from tables based on max value of another column
I have two tables and I want column input from first_table and column output from second_table based on the latest finished time first_table: second_table result_table I am trying to use this query: Answer You can use a correlated subquery in the on clause of the join: For performance here, you want an index on second_table(id, finished_time). This can also be
Row lumping, cycle dates
I want to look at the lead type and if that type is the same for that row then merge in those dates to fit within one row. I have the below table: Expected Results: How can I get my output to look like the expected results? I have tested withlead lag rank and case expression but nothing worthy of
How to pull the latest records added in a table?
I want to pull the records associated with the latest VERSION_ID. FILE_EXTRACT_VERSION table looks like this: FILE_EXTRACT_VERSION_SPECS table looks like this: I want to write a query to pull records with the latest VERSION_ID (latest can be segregated by the latest date they have been added) Here is what I have tried but it gives an error: Only one expression