Home >Database >Mysql Tutorial >select-mysql 按月分组,取每月日期小的

select-mysql 按月分组,取每月日期小的

WBOY
WBOYOriginal
2016-06-06 09:40:18984browse

mysqlselect

DROP TABLE IF EXISTS t_test;

/*!40101 SET @saved_cs_client = @@character_set_client /;
/
!40101 SET character_set_client = utf8 /;
CREATE TABLE t_test (
id int(11) NOT NULL AUTO_INCREMENT,
org varchar(10) DEFAULT NULL,
status date DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
/
!40101 SET character_set_client = @saved_cs_client */;

-- Dumping data for table t_test

LOCK TABLES t_test WRITE;
/*!40000 ALTER TABLE t_test DISABLE KEYS /;
INSERT INTO t_test VALUES (1,'qwe','2015-02-09'),(2,'qqq','2015-03-03'),(3,'www','2012-02-11'),(4,'qwe','2015-03-10'),(5,'asd','2015-04-10'),(6,'fff','2015-05-10'),(7,'aaa','2015-10-10'),(8,'fff','2015-03-10'),(9,'www','2012-02-01'),(10,'asd','2015-03-02'),(11,'qwe','2015-03-26'),(12,'www','2012-03-11');
/
!40000 ALTER TABLE t_test ENABLE KEYS */;
UNLOCK TABLES;

<code></code>

上面是表里面测试数据,按照月份分组,取每个月日期最小的数据

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn