Get rows from current month if older is not available

Get rows from current month if older is not available

Content Index :

Get rows from current month if older is not available
Tag : sql , By : lewing
Date : November 28 2020, 11:01 PM

wish helps you I have a table that looks like this: , Another way using MAX
WITH tbl AS (
    SELECT TO_DATE('2016-10-01', 'YYYY-MM-DD') AS "month", 20 AS amount FROM dual
    SELECT TO_DATE('2016-08-01', 'YYYY-MM-DD') AS "month", 10 AS amount FROM dual    
    SELECT TO_DATE('2016-07-01', 'YYYY-MM-DD') AS "month", 5 AS amount FROM dual        
  FROM tbl
 WHERE TRUNC("month", 'MONTH') = NVL((SELECT MAX(t."month") 
                                        FROM  tbl t 
                                       WHERE t."month" < TRUNC(SYSDATE, 'MONTH')), 
                                     TRUNC(SYSDATE, 'MONTH'));

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Check if older or newer date than current (by month)

Tag : php , By : KT.
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I want to check if given date (like 2012-12) is older or newer than current date. , You forgot to add the + to your strtotime function.
if(strtotime('2013-02')>strtotime('+1 Months')){
   echo "true";
} else {
    echo "false";
$date = "2012/02/01";

if(date("n", strtotime($date)) != date("n")) {
 echo 'not current month';
$date = "2012/02/01";

if(date('d-m-Y', strtotime($date)) != date('d-m-Y')) {
 echo 'not current day';

SQL Server Delete rows when timestamp is older than 1 month

Tag : sql , By : hellboy32
Date : March 29 2020, 07:55 AM
wish of those help Rounding issues with the month function may give you issues - you'd probably be better off with a DATEADD() instead, e.g.,

Comparing current Month and previous Month's rows on a column, SQL Server 2012

Tag : sql , By : scotta01
Date : March 29 2020, 07:55 AM
I hope this helps you . I need some guidance and help with a question I am not entirely sure how to solve in SQL Server 2012. I think LAG and LEAD functions could be useful but I am not sure. , I think you can use a query like this:
        WHEN Active <> 0 AND 
             ISNULL(LAG(Active) OVER (PARTITION BY LocationCode ORDER BY YearMonth), 0) = 0 THEN 1 
        ELSE 0 
    END As New
FROM yourTable;

How to delete the rows older then 1 month?

Tag : sql-server , By : B3CFT
Date : March 29 2020, 07:55 AM
wish helps you I have One Table Login in this table i want to delete rows older then 1 months. , Use DateAdd. Try
SELECT CONVERT(Datetime, '2015-10-29 15:01:00', 120)

Delete rows older than 1 month

Tag : sql , By : DaveF
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • SSIS Error on insertion - Error when new primary keys in Dimension table
  • How can I make a temp table of specific datetime data within a range?
  • AnalysisException: Syntax error in SQL After multiple join
  • SQL Query Multiple Columns Using Distinct on One Column Only and Using Order By
  • Sum inventory item groups
  • TSQL: Parsing strings with various characters
  • Using SQL Server : how to use select criteria based on sum
  • Inserting dynamic pivot Result into Temp table
  • Joining multiple fields in a dataset joined with descriptions
  • Conditional WHERE EXISTS in Oracle query
  • How to get the count of each unique value in a column between two dates?
  • SQL: Select only if multiple values are IN 1 column from CatalogTable
  • In a query (no editing of tables) how do I join data without any similarities?
  • Create nested json blobs in PostgreSQL
  • Getting extra dates while using cte
  • Way to alter one table if another was altered
  • Proper use of semicolons in functions and procedures
  • Cursor Not looping all the Records
  • Select inner join returns wrong result
  • Group By showing duplicates
  • Error in using subquery in access join query
  • How do I use a composite pk in a stored procedure?
  • Oracle Unique Indexes
  • Spooling data to CSV truncates
  • How do views reduce code duplication?
  • SQL: Gather right hand values from a join
  • SQL Agent Logon - What is going on?
  • How do I combine two rows of same part, but add quantities?
  • How to optimize this SQL query for a rectangular region?
  • Pass data from ssrs subreport to parent
  • how to enter values in rowguid column?
  • Read multiple tables from dataset in Powershell
  • In SQL how to I exclude a record if there are more than 3 characters after a dash
  • What is the difference between check and foreign key?
  • How to return a record from function, executed by INSERT/UPDATE rule (trigger)?
  • SQL order by oldest from Unix Timestamps
  • How to convert decode function in oracle to standard big query
  • Postgresql: An alternative to subqueries to make the query more efficient?
  • Use returned values from a query in the same procedure
  • Sum all numeric columns in database and log results
  • Release item in current year
  • Conditional function not working as intended postgresql
  • SQL trigger, results not Grouped by
  • getting more records than expected with simple query in postgresql
  • get first occurrence of a certain combination of columns
  • Converting string timestamp to local-time zone in Oracle
  • Redshift - Filter out rows that are blank to left or right of a character
  • Teradata - Know the load volume by times of a table
  • How do I replace duplicate data with random data of same length in SQL
  • How to group by using pivot table
  • How can I achieve a Join for merging two tables FULL OUTER JOIN and avoid duplicates?
  • Multi Keyword search on multi-column sql
  • Computing the median of salaries under each manager in BigQuery SQL
  • How can insert value by selecting from another
  • Retrieving only the latest item for a set of data
  • update column with concatenating for that group only
  • SQL `SELECT 'some string value' AS fieldname` equivalent in Powershell?
  • How to determine the AVERAGE number of associated records
  • In Django, how can I build a set of criteria from a list?
  • Using replace() inside a loop
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com