If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL find unused months

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-18-11, 07:27
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Question MySQL find unused months

Is there an way to use an MySQL query to find the missing months between 2 dates in an table?
Reply With Quote
  #2 (permalink)  
Old 05-18-11, 12:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, it's easy if you use an auxiliary numbers table...
Code:
CREATE TABLE numbers ( n INTEGER NOT NULL PRIMARY KEY );
INSERT INTO numbers VALUES (0),(1),(2),(3),(4),(5),(6),(7),... ;]
could you do a SHOW CREATE TABLE for your table please?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-18-11, 16:47
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
It's about this table:

CREATE TABLE IF NOT EXISTS `iso_werkplekinspecties` (
`id` int(3) NOT NULL AUTO_INCREMENT,
`datum` date NOT NULL,
`ehbo_doos` varchar(3) NOT NULL,
`looppaden` varchar(3) NOT NULL,
`blus_app` varchar(3) NOT NULL,
`nooduitgang` varchar(3) NOT NULL,
`geluidsniveau` varchar(3) NOT NULL,
`potentieel` varchar(3) NOT NULL,
`pbm` varchar(3) NOT NULL,
`loopgang` varchar(10) NOT NULL,
`verlengkabel` varchar(10) NOT NULL,
`afval` varchar(10) NOT NULL,
`positie` varchar(10) NOT NULL,
`opmerkingen` varchar(255) NOT NULL,
`status` varchar(15) NOT NULL,
`user_id` int(2) NOT NULL,
`user_id_rejected` int(2) NOT NULL,
`updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

This is my date field:
`datum` date NOT NULL,

Thanks for helping me out!!
Reply With Quote
  #4 (permalink)  
Old 05-18-11, 17:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
find the missing months between which two dates?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 05-19-11, 01:28
Muiter Muiter is offline
Registered User
 
Join Date: Dec 2008
Location: Netherlands
Posts: 56
Date one is the oldest date in the field 'datum'. The second date is NOW() + 3 months.
Reply With Quote
  #6 (permalink)  
Old 05-20-11, 10:34
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
okay, we'll get there, in stages

could you please run this query and report what it produces...
Code:
SELECT EXTRACT(YEAR_MONTH FROM datum)) AS from_yyyymm
     , COUNT(*) AS rows
  FROM iso_werkplekinspecties 
GROUP
    BY from_yyyymm ASC
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On