簡單按日期查詢mysql某張表中的記錄數

來源:互聯網
上載者:User

標籤:UI   select   查詢   typeid   cacti   測試   txt   status   word   

測試表表結構:
mysql> show create table dr_stats\G
1. row

       Table: dr_statsCreate Table: CREATE TABLE `dr_stats` (  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,  `views` int(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘展示量‘,  `num` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘計費量‘,  `advnum` int(10) NOT NULL DEFAULT ‘0‘ COMMENT ‘廣告商計費數‘,  `clicks` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘點擊量‘,  `do2click` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘二次點擊量‘,  `day` date NOT NULL DEFAULT ‘0000-00-00‘ COMMENT ‘計費日期‘,  `planid` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘計劃ID‘,  `uid` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘站長ID‘,  `siteid` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘網站ID‘,  `zoneid` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘廣告位ID‘,  `adstypeid` mediumint(8) NOT NULL COMMENT ‘廣告類型ID‘,  `deduction` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘扣量‘,  `sumprofit` decimal(10,4) NOT NULL DEFAULT ‘0.0000‘ COMMENT ‘扣量金額‘,  `sumpay` decimal(10,4) NOT NULL DEFAULT ‘0.0000‘ COMMENT ‘計費金額‘,  `sumadvpay` decimal(10,4) NOT NULL DEFAULT ‘0.0000‘ COMMENT ‘計費總金額‘,  `status` tinyint(1) NOT NULL DEFAULT ‘0‘ COMMENT ‘是否已結算‘,  `dosage` mediumint(8) NOT NULL DEFAULT ‘0‘ COMMENT ‘補量‘,  `sumdosage` decimal(10,4) NOT NULL DEFAULT ‘0.0000‘ COMMENT ‘補量金額‘,  `pclick` int(8) NOT NULL DEFAULT ‘0‘,  PRIMARY KEY (`id`),  UNIQUE KEY `day` (`day`,`planid`,`uid`,`siteid`,`zoneid`,`adstypeid`),  KEY `planid_uid` (`planid`,`uid`)) ENGINE=InnoDB AUTO_INCREMENT=9298495886 DEFAULT CHARSET=utf8 COMMENT=‘網站結算‘1 row in set (0.00 sec)

查詢一張表中一年的中4月份的資料:

mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select * from dr_stats where 1 and month(day)=04;‘查詢一張表中一年的中5月份有多少條記錄:[[email protected] ~]# time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where 1 and month(day)=05;‘Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|  1071903 |+----------+[[email protected] ~]# time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where 1 and month(day)=05 and  day(day)  between 1 and 31;‘Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|  1071903 |+----------+

查詢dr_stats表2016年 4月1日至2016年4月21日的資料記錄數:

time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where 1 and year(day)=2016 and month(day)=04 and  day(day)  between 1 and 21;‘ Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|        0 |+----------+

2016年 4月1日至2016年4月21日這個dr_stats表是沒有資料的

查詢dr_stats表2016年 4月1日至2016年4月22日的資料記錄數:

time mysql -uroot -p‘ZykJ(5678%$#@!)cpv17‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where 1 and year(day)=2016 and month(day)=04 and  day(day)  between 1 and 22;‘ Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|       95 |+----------+

查詢dr_stats表2016年 4月22日至2016年4月23日的資料:
time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select * from dr_stats where 1 and year(day)=2016 and month(day)=04 and day(day) between 22 and 23;‘ >>/root/txt04

查詢dr_stats表2016年 4月22日至2016年4月22日的資料:

[[email protected] www]# time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where day>="2016-04-22" and day<="2016-04-22";‘Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|       95 |+----------+

查詢dr_stats表2016年 4月21日至2016年4月22日的資料:

time mysql -uroot -p‘ZykJ7‘ -S /tmp/mysql.sock -e ‘use drnew;select count(*) from dr_stats where day>="2016-04-21" and day<="2016-04-22";‘Warning: Using a password on the command line interface can be insecure.+----------+| count(*) |+----------+|       95 |+----------```+

簡單按日期查詢mysql某張表中的記錄數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.