This is a discussion on Newbie needs code clarified within the MySQL forums, part of the Database Server Software category; --> I placed a "got it" comment on the lines where I understand the What AND Why. For all others, ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I placed a "got it" comment on the lines where I understand the What AND Why. For all others, I had a little trouble fully comprehending what I found in the MySQL Manual, so I'm looking for some further explanation. Feel free to explain as if I were completely daft, because sometimes, I fear I may be ;-) ***START CODE*** drop table if exists Dates; // got it create table Dates ( // got it id int(11) not null auto_increment primary key, // got it dt datetime not NULL) // got it engine=myisam; // why declare? delimiter $ $ // what and why? drop procedure if exists make_dates $$ // why end in $$? CREATE PROCEDURE make_dates(max_recs int) // what is (max_recs int) all about? begin // got it DECLARE start_dt datetime; // got it DECLARE numrecs int default 1; // got it SET start_dt = date_format( now() - interval max_recs minute, '%Y-%m- %d %H:%i:00'); // i need a further explanation for "interval" INSERT into Dates (dt) values (start_dt ); // got it WHILE numrecs < max_recs // got it DO // got it INSERT into Dates (dt) // got it SELECT dt + interval ( numrecs ) minute // please explain "( numrecs ) minute" FROM dates; // got it SELECT count(*) into numrecs // should this become another INSERT statement? FROM dates; // got it SELECT numrecs; // why? end WHILE; // got it end $$delimiter; ***END CODE*** This code is from: http://datacharmer.blogspot.com/2006...s-quickly.html, which I was directed to from another post. I thought I wasn't going to need to use this, but after all, it turns out that I may. I'd like to gain an understanding so that I can confidently customize it to our use. ~Mo |
| ||||
| On May 21, 2:29 pm, Mo <Mehile.Orl...@gmail.com> wrote: > I placed a "got it" comment on the lines where I understand the What > AND Why. > For all others, I had a little trouble fully comprehending what I > found in the MySQL Manual, so I'm looking for some further > explanation. > > Feel free to explain as if I were completely daft, because sometimes, > I fear I may be ;-) > > ***START CODE*** > > drop table if exists > Dates; // got it > create table Dates > ( // got it > id int(11) not null auto_increment primary key, // got it > dt datetime not NULL) // got it > engine=myisam; // why declare? > delimiter $ > $ // what > and why? > drop procedure if exists make_dates $$ // why end > in $$? > CREATE PROCEDURE make_dates(max_recs int) // what is (max_recs int) > all about? > begin // > got it > DECLARE start_dt datetime; // got it > DECLARE numrecs int default 1; // got it > SET start_dt = date_format( now() - interval max_recs minute, '%Y-%m- > %d %H:%i:00'); > // > i need a further explanation for "interval" > INSERT into Dates (dt) values (start_dt ); // got it > WHILE numrecs < max_recs // got it > DO // > got it > INSERT into Dates (dt) // got it > SELECT dt + interval ( numrecs ) minute > // > please explain "( numrecs ) minute" > FROM dates; // got it > SELECT count(*) into numrecs // should this become another INSERT > statement? > FROM dates; // got it > SELECT numrecs; // why? > end WHILE; // got > it > end $$delimiter; > > ***END CODE*** > > This code is from:http://datacharmer.blogspot.com/2006...s-quickly.html, > which I was directed to from another post. > I thought I wasn't going to need to use this, but after all, it turns > out that I may. > I'd like to gain an understanding so that I can confidently customize > it to our use. > > ~Mo You would probably get more help if you asked one major question at a time. Try to understand what one section of code does and if you have questions ask them underneath the code all together in one place. The part that you get is immaterial, the part you don't get is what you want to focus on. The code is hard to read with the "got its" added after it goes through the email it gets wrapped and the lines break different than when you said it. Try to keep your code as clean as possible so the people helping you don't have to squint :-) Where you say " I need further explanation for interval" that should be at the bottom so people can read your code. It is just to difficult to try to help you. Try rephrazing your questions. |
| Thread Tools | |
| Display Modes | |
|
|