MySQL Query last week (last 7 days) data

Source: Internet
Author: User
Tags mysql query

Ref: 77638826

-Table structure

-

CREATE TABLE' Zk_score ' (' ID ')varchar(255) not NULLCOMMENT'Rating Table', ' name 'varchar(255)DEFAULT NULLCOMMENT'Name of Institution', ' TOTALSCR 'varchar(255)DEFAULT NULLCOMMENT'Comprehensive score', ' Unfiorm 'varchar(255)DEFAULT NULLCOMMENT'Consistency', ' complete 'varchar(255)DEFAULT NULLCOMMENT'completeness', ' standard 'varchar(255)DEFAULT NULLCOMMENT'Normative', ' timely 'varchar(255)DEFAULT NULLCOMMENT'timeliness of', ' rank 'varchar(255)DEFAULT NULLCOMMENT'ranking', ' Createtime 'varchar(255)DEFAULT NULLCOMMENT'Update Time', ' status 'varchar(255)DEFAULT NULLCOMMENT'Status',  PRIMARY KEY(' id ') USING BTREE) ENGINE=InnoDBDEFAULTCHARSET=UTF8 Row_format=DYNAMIC;

-Table Data

-

-sql

-

SelectA.click_date as datetime, Ifnull (B.TOTALSCR,0) asTotalscr, Ifnull (B.standard,0) asStandard , Ifnull (B.complete,0) asComplete , Ifnull (B.unfiorm,0) asUnfiorm, Ifnull (b.timely,0) asTimely from (    SELECTCurdate () asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval1  Day) asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval2  Day) asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval3  Day) asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval4  Day) asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval5  Day) asclick_dateUnion  All    SELECTDate_sub (Curdate (), Interval6  Day) asclick_date) A Left Join (  SelectDate (Createtime) as datetime,            AVG(TOTALSCR) TOTALSCR,AVG(Standard),AVGComplete ,AVG(Unfiorm) Unfiorm,AVG(timely) Timely fromZk_scoreGroup  byDate (createtime)) b onA.click_date=B.datetime ORDER  byA.click_dateASC;

-Query Results

-

-Get nearly 7 days another SQL

-

SELECT    @num:= @num + 1, Date_format (Date_sub (curdate ()+1, INTERVAL@num  Day),'%y-%m-%d') asDate fromZk_monit, (SELECT @num:= 0) TWHEREdate_sub (curdate ()+1, INTERVAL@num  Day)<=Date_format (Curdate ()+1,'%y-%m-%d' )      and @num <7ORDER  byDateDESC;

MySQL Query last week (last 7 days) data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.