Date_format (From_unixtime (createdate), '%y-%m ') = Date_format (now (), '%y-%m ') month
Date (From_unixtime (L. ' CreateDate ')) =date (now ()) Day
WEEK (Date (from_unixtime (' CreateDate ')), 1) = WEEK (Date (now ()), 1) Week
Sp:
BEGIN
#1, representing the day, 2 for the month, 3 for the quarter
#SET @mycnt = 0;
# (@mycnt: = @mycnt + 1) as rank
IF _type = 1 Then
# Select Unix_timestamp ("2014-07-04");
#leave sp;
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left JOIN Dog_member as M in L.memberid = M.id WHERE DATE (From_unixtime (L. ' CreateDate ')) =date (now ()) GROUP B Y l.memberid ORDER BY loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
ELSEIF _type = 2 Then
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left joins Dog_member as M on l.memberid = m.id WHERE date_format (From_unixtime (L. ' CreateDate '), "%y-%m") = DA Te_format (now (), "%y-%m") GROUP by L.memberid ORDER by loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
ELSEIF _type = 3 Then
IF Date_format (now (), '%y-%m ') >= Date_format (now (), "%y-01") and Date_format (now (), '%y-%m ') <= Date_format (now () , "%y-03") Then
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left joins Dog_member as M on l.memberid = m.id WHERE date_format (From_unixtime (L. ' CreateDate '), "%y-%m") > = Date_format (now (), "%y-01") and Date_format (From_unixtime (L. ' CreateDate '), "%y-%m") <= Date_format (now (), "%y-03" GROUP by L.memberid ORDER by loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
ELSEIF Date_format (now (), '%y-%m ') >= Date_format (now (), '%y-04 ') and Date_format (now (), '%y-%m ') <= date_format ( Now (), '%y-06 ') then
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left joins Dog_member as M on l.memberid = m.id WHERE date_format (From_unixtime (L. ' CreateDate '), "%y-%m") > = Date_format (now (), "%y-04") and Date_format (From_unixtime (L. ' CreateDate '), "%y-%m") <= Date_format (now (), "%y-06" GROUP by L. ' MemberID ' ORDER by loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
ELSEIF Date_format (now (), '%y-%m ') >= Date_format (now (), "%y-07") and Date_format (now (), '%y-%m ') <= date_format ( Now (), "%y-09") Then
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left joins Dog_member as M on l.memberid = m.id WHERE date_format (From_unixtime (L. ' CreateDate '), "%y-%m") > = Date_format (now (), "%y-07") and Date_format (From_unixtime (L. ' CreateDate '), "%y-%m") <= Date_format (now (), "%y-09" GROUP by L.memberid ORDER by loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
ELSEIF Date_format (now (), '%y-%m ') >= Date_format (now (), "%y-10") and Date_format (now (), '%y-%m ') <= date_format ( Now (), "%y-12") Then
SET @query = ' SELECT L. ' MemberID ', sum (L. ' Loginlong ') as loginlongtotal,m.name as membername,m.photo as Memberphoto from do G_login as L left joins Dog_member as M on l.memberid = m.id WHERE date_format (From_unixtime (L. ' CreateDate '), "%y-%m") > = Date_format (now (), "%y-10") and Date_format (From_unixtime (L. ' CreateDate '), "%y-%m") <= Date_format (now (), "%y-12" GROUP by L.memberid ORDER by loginlongtotal Desc ';
SET @limit = CONCAT (' Limit ', (_page-1) *_limit, ', ', _limit);
SET @query = CONCAT (@query, @limit);
END IF;
ELSE
LEAVE SP;
END IF;
PREPARE stmt from @query;
EXECUTE stmt;
IF Row_count () <> 1
Then SET _RTN = 1300;
LEAVE SP;
END IF;
SET _rtn = 1;
SELECT _rtn;
END
Sp:
BEGIN
SET @d = "Day";
SET @w = "Week";
SET @m = "month";
SET @y = "Year";
(SELECT ' Stepnum ', from_unixtime (' CreateDate ') as createdate,@d as Mark from Dog_pedometer WHERE DATE (From_unixtime (' CreateDate ') = DATE (now ()) and Kalaid = _kalaid and MemberID = _memberid ORDER by ' stepnum ' desc limit 1)
Union
(SELECT ' Stepnum ', from_unixtime (' CreateDate ') as createdate,@w as Mark from Dog_pedometer WHERE WEEK (DATE (from_unixtime (' CreateDate ')), 1) = WEEK (DATE (now ()), 1) and Kalaid = _kalaid and MemberID = _memberid ORDER by ' stepnum ' desc limit 1)
Union
(SELECT ' Stepnum ', from_unixtime (' CreateDate ') as createdate,@m as Mark from Dog_pedometer WHERE date_format (from_ Unixtime (' CreateDate '), '%y-%m ') = Date_format (now (), '%y-%m ') and Kalaid = _kalaid and MemberID = _memberid ORDER by ' STEPN Um ' desc LIMIT 1)
Union
(SELECT ' Stepnum ', from_unixtime (' CreateDate ') as createdate,@y as Mark from Dog_pedometer WHERE date_format (from_ Unixtime (' CreateDate '), '%Y ') = Date_format (now (), '%Y ') and Kalaid = _kalaid and MemberID = _memberid ORDER by ' stepnum ' de SC limit 1);
IF Row_count () <> 1 Then
SET _RTN = 1300;
LEAVE SP;
END IF;
SET _rtn = 1;
SELECT _rtn;
END
MySQL under the Sun Lunar Year Week query