logo
down
shadow

months between initial and final month


months between initial and final month

Content Index :

months between initial and final month
Tag : mysql , By : jbcrail
Date : November 29 2020, 04:01 AM

like below fixes the issue To solve this you need to create a table of month numbers, then JOIN that to the species table to get a list of species flowering by month. In my demo on dbfiddle I've created a VIEW called flowering_species which you can then query by species_id or month:
CREATE VIEW flowering_species AS
SELECT s.id AS species_id, s.name AS name, m.month AS month
FROM (SELECT 1 AS month UNION SELECT 2 UNION SELECT 3 UNION 
      SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION 
      SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION 
      SELECT 10 UNION SELECT 11 UNION SELECT 12) m
JOIN species s ON m.month BETWEEN s.FloweringInitialMonth AND s.FloweringFinalMonth
               OR s.FloweringInitialMonth AND s.FloweringFinalMonth = 13
ORDER BY species_id, month
SELECT * FROM flowering_species WHERE month = 6
SELECT * FROM flowering_species WHERE species_id = 20
species_id  name                    month
1           Test species            6
20          Equisetum palustre      6
314         Holcus annuus           6
1825        Cirsium vuloare         6
2237        Agapanthus africanus    6
3126        Centaurea malacitana    6

species_id  name                    month
20          Equisetum palustre      4
20          Equisetum palustre      5
20          Equisetum palustre      6

Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

Parameter month selection: Make a query that shows previous month, 12 months ago and last 12 months average


Tag : sql , By : user158220
Date : March 29 2020, 07:55 AM
help you fix your problem I wanted to play around with my Total_Sales table. This is how the data looks like (using SQL Server 2008 R2)
SELECT
  [this_month].*,
  [last_month].Sales        AS [prev_month_sales],
  [last_year].Sales         AS [month_last_year_sales],
  [yearly].AverageSales     AS [last_12_month_average]
FROM
  Total_Sales     AS [this_month]
LEFT JOIN
  Total_Sales     AS [last_month]
    ON  [last_month].Name = [this_month].Name
    AND (
         ([last_month].Year = [this_month].Year     AND [last_month].Month = [this_month].Month - 1)
      OR ([last_month].Year = [this_month].Year - 1 AND [last_month].Month = 12 AND [this_month].Month = 1)
    )
LEFT JOIN
  TotalSales     AS [last_year]
    ON  [last_year].Name  = [this_month].Name
    AND [last_year].Year  = [this_month].Year - 1
    AND [last_year].Month = [this_month].Month
CROSS APPLY
(
  SELECT
    AVG(Sales) AS AverageSales
  FROM
    Total_Sales
  WHERE
    Name = [this_month].Name
    AND (
            (Year = [this_month].Year     AND Month <= [this_month].Month)
         OR (Year = [this_month].Year - 1 AND Month >  [this_month].Month)
    )
)
  AS [yearly]
Last Month : MonthStart = DATEADD(MONTH, -1, ThisMonth)
A Year Ago : MonthStart = DATEADD(YEAR,  -1, ThisMonth)
Last Year  : MonthStart > DATEADD(YEAR,  -1, ThisMonth) AND MonthStart <= ThisMonth

T-SQL query to select last 3 months of data, last years month, averages of this month and average of all months


Tag : sql , By : Derek
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , you need something along these lines .Not the optimum solution but will give you a start .This is a static solution but it looks like you may want a dynamic solution
*not tested
 SELECT 
 Category
,[Sep 2012]=SUM(CASE WHEN YEAR(TranDate)= YEAR(GETDATE()) AND MONTH(TranDate)= MONTH(GETDATE()) THEN Amount ELSE NULL END)
,[Aug 2012]=SUM(CASE WHEN  YEAR(TranDate)= YEAR(DATEADD(month,-1,GETDATE())) AND MONTH(TranDate)= MONTH(DATEADD(month,-1,GETDATE()))  THEN Amount ELSE NULL END)
,[Jul 2012]=SUM(CASE WHEN YEAR(TranDate)= YEAR(DATEADD(month,-2,GETDATE())) AND MONTH(TranDate)= MONTH(DATEADD(month,-2,GETDATE())) THEN Amount ELSE NULL END)
,[AVG Sep 2012]=AVG(CASE WHEN YEAR(TranDate)= YEAR(GETDATE()) AND MONTH(TranDate)= MONTH(GETDATE()) THEN Amount ELSE NULL END)
,[AVG 12 months]=AVG(CASE WHEN TranDatee > CAST(DATEADD(year,-1,GETDATE()) AS DATE) THEN Amount ELSE NULL END)/12
FROM Table1
GROUP BY Category,Amount

Can I label months in a ggplot with the initial of each month and maintain the order?


Tag : r , By : John Bentley
Date : March 29 2020, 07:55 AM
will be helpful for those in need If your month values are numeric then you can do this at the plotting stage by modifying the labels. In your ggplot add the following:
+ scale_x_continuous(breaks = 1:12, 
                     labels = c('J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'))

Swift 4: Checking if week, month, 2 months, etc. has passed since initial launch using Calendar


Tag : ios , By : Matthew Steed
Date : March 29 2020, 07:55 AM
I wish did fix the issue. From what I understand of your question, you want a button to display if they have had the app for more than a certain amount of time. If that is the case, I've written some code that will be helpful to you:
let timeSinceInstalled = -(installedDate ?? Date()).timeIntervalSinceNow

Button1.isHidden = timeSinceInstalled < 604800
Button2.isHidden = timeSinceInstalled < 2592000
Button3.isHidden = timeSinceInstalled < 5184000
override func viewDidLoad() {
    super.viewDidLoad()
    let timeSinceInstalled = -(installedDate ?? Date()).timeIntervalSinceNow
    Button1.isHidden = timeSinceInstalled < 604800
    Button2.isHidden = timeSinceInstalled < 2592000
    Button3.isHidden = timeSinceInstalled < 5184000
}

var installedDate: Date? {
    get {
        return UserDefaults.standard.object(forKey: "installedDateKey") as? Date
    }
    set {
        UserDefaults.standard.set(newValue, forKey: "installedDateKey")
    }
}
override func viewDidLoad() {
    super.viewDidLoad()
    let timeSinceInstalled = -(installedDate ?? Date()).timeIntervalSinceNow
    setTitle(Button1, timeSinceInstalled < 604800)
    setTitle(Button2, timeSinceInstalled < 2592000)
    setTitle(Button3, timeSinceInstalled < 5184000)
}

func setTitle(_ button: UIButton, _ statement: Bool) {
    button.setTitle(statement ? "You have none available" : "Click me", for: .normal)
    button.isEnabled = !statement
}

var installedDate: Date? {
    get {
        return UserDefaults.standard.object(forKey: "installedDateKey") as? Date
    }
    set {
        UserDefaults.standard.set(newValue, forKey: "installedDateKey")
    }
}

How to get next 4 months from current month in an array of month objects [{month:'Jan' id:'1},{month:'Feb', id:'2},...{m


Tag : javascript , By : user181706
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I tried array slice but its not giving expected result if starting month is one of the last 3 months of the year. , Simply double the array and then slice it
var newArr = [ ...arr, ...arr ];
var index = 10;
var output = newArr.slice( index, index + 4 )
var arr = [{
  month: 'Jan',
  id: "1"
}, {
  month: 'Feb',
  id: "2"
}, {
  month: 'Mar',
  id: "3"
}, {
  month: 'Apr',
  id: "4"
}, {
  month: 'May',
  id: "5"
}, {
  month: 'Jun',
  id: "6"
}, {
  month: 'Jul',
  id: "7"
}, {
  month: 'Aug',
  id: "8"
}, {
  month: 'Sep',
  id: "9"
}, {
  month: 'Oct',
  id: "10"
}, {
  month: 'Nov',
  id: "11"
}, {
  month: 'Dec',
  id: "12"
}];

var newArr = [ ...arr, ...arr ];
//console.log( newArr );
var index = 10;
var output = newArr.slice(index, index+4);

console.log( output );
var newArr = arr.concat(arr.slice())
Related Posts Related QUESTIONS :
  • getting error in Sql Query incorrect syntax near ')'
  • MariaDB/MySQL select query replace json array of ids into concatenated values
  • How to create a MySQL Query to get sales for each date of month (Like Calendar)?
  • Insert query fails with error duplicate entry , where as select query returns null
  • MySQL - ORDER BY multiple words, then alphabetically?
  • With a one-to-many relation, how do you get every row of table A if table B doesn't reference some rows of A?
  • How to add temporary column with data with MYSQL?
  • Why is subquery join much faster than direct join
  • Under standing Update Queries, and how many sets one query can have
  • How to select multiple values in a subquery but have each value assigned to matching parent select value?
  • SQL getting a column to match multiple conditions in CASE
  • Converting date operation from MySQL to PostgreSQL
  • MySQL - Join these subqueries into a single query
  • Show the list of all product's names ordered along with first and last names of the customers
  • Mysql `OR` condition doesn't work with JOIN
  • how can I hide the data that my controller returns making a CRUD in Laravel & vue.js?
  • Sum of values for all accounts using the most recent date for each
  • MySQL Query between three tables (with also ORDER and LIMIT)
  • MySQL date_format () function vs SQL Like operator
  • How to Combine two select and two where clause?
  • How to convert this (strange formated) data ? a:5:{s:15:"nc_notification";s:1:"2";s:20:"iso_add
  • SELECT result within select isn't reachable?
  • How to call stored procedure at sqlfiddle?
  • How Do I convert this table from row to column?
  • Mysql check if table has any value
  • Mysql Index misbehave in rails
  • Calculate number of students per class without using a JOIN
  • "new ephemeral certificate expires too soon: current time:"M
  • How to write this SQL (about date and time)?
  • What would take longer to execute in a million row table LIMIT 37,22 or LIMIT 100037,22
  • Can't connect a spring-boot 2 service to mysql in a different container
  • Insert statement using variable in sql query
  • Getting all users except admins in many-to-many relationship
  • How to pass the data from modal to MYSQL using VueJS
  • MYSQL - get a row from a table in every database
  • date type casting in npm package?
  • GROUP BY a, b VS GROUP BY b, a
  • How to store multiple values on a mysql table
  • 2 SELECT in a query with ORDER BY
  • BigQuery: How to run cohort / retention analysis for userbase across 2.5 years?
  • Can't connect local database. Sequel Pro encountered an unexpected error
  • How do I change the auto increment counter in MySQL from +1 to +43
  • How to query non duplicate rows but keep the primary key
  • How to group all scores by username in a table and display rank?
  • How to remove timestamp with the date using sql query?
  • Modify SQL query to get data only from past 2 months
  • change engine type from MyISAM to InnoDB
  • Need mysql query to find total sum as per matched query
  • json_table syntax and structure
  • Is there any way in sql query to rank certain value in ordered set of records such that ranking reset after it encounter
  • not able to login in google cloud storage sql instance
  • Inserting data into MySQL database with VBA
  • Make (user_id&music_id) unique in Likes table and Dislikes table
  • Can't do 50k insertion using bulkCreate
  • SQL syntax to get data IN date
  • How to get 4-byte emojis to store correctly in mysql 5.7?
  • How to create an in-memory database for PHPUnit testing?
  • How to write an SQL query to fetch the id in a column that has all the required data in some other column?
  • Invalid COLUMN in the select list because it is not contained in either an aggregate function or the GROUP BY clause
  • How to get actual index number of rows in MySQL when using Where clause
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com