-1

查询 1

SELECT SessionInfo.IVRSessionInfoID
FROM   SessionInfo
WHERE  SessionCallTime BETWEEN UNIX_TIMESTAMP('2013-08-01 00:00:00') 
                           AND UNIX_TIMESTAMP('2013-08-01 23:59:59')
ORDER  BY SessionInfo.SessionCallTime DESC;

查询 2

SELECT SessionInfo.IVRSessionInfoID
FROM   SessionInfo
WHERE  ( SessionInfo.SessionCallTime BETWEEN '2013-08-01 00:00:00' 
                                         AND '2013-08-01 23:59:59' )
ORDER  BY SessionInfo.SessionCallTime DESC; 

有什么区别?为什么第一个查询给出 0 行,第二个给出记录?

在此表中,这两个日期之间有 20000 行。

表模式

 CREATE TABLE `SessionInfo` (
 `IVRSessionInfoID` bigint(8) unsigned NOT NULL AUTO_INCREMENT,
`SessionCallTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`MGServerIP` varchar(15) NOT NULL,
`MGServerPort` smallint(2) unsigned NOT NULL DEFAULT '5060',
 `SessionUniqueID` varchar(64) NOT NULL,
`ANI` varchar(20) NOT NULL,
 `CountryID` int(4) unsigned DEFAULT NULL,
 `CountryStateAreaID` int(4) unsigned DEFAULT NULL,
 `AccessNumberProviderLogID` int(4) unsigned DEFAULT NULL,
 `AccessNumberLogID` int(4) unsigned DEFAULT NULL,
  `AccessRestrictionLogID` int(4) unsigned DEFAULT NULL,
 `SubscriberCardID` bigint(8) unsigned DEFAULT NULL,
  `SessionDuration` int(4) unsigned NOT NULL,
  `SessionRNDDuration` int(4) unsigned NOT NULL,
    `TotalCharge` decimal(15,6) unsigned NOT NULL,
   `RuleSetLogID` int(4) unsigned DEFAULT NULL,
  `RuleSetChargeInfoLogID` int(4) unsigned DEFAULT NULL,
 `RuleSetRNDDuration` int(4) unsigned NOT NULL,
 `RuleSetTotalCharge` decimal(15,6) unsigned NOT NULL,
  PRIMARY KEY (`IVRSessionInfoID`),
  UNIQUE KEY `UNIQUE` (`SessionUniqueID`),
 KEY `SessionCallTime` (`SessionCallTime`),
 KEY `ANI` (`ANI`),
 KEY `CountryID` (`CountryID`),
KEY `CountryStateAreaID` (`CountryStateAreaID`),
  KEY `AccessNumberProviderLogID` (`AccessNumberProviderLogID`),
 KEY `AccessNumberLogID` (`AccessNumberLogID`),
KEY `AccessRestrictionLogID` (`AccessRestrictionLogID`),
 KEY `SubscriberCardID` (`SubscriberCardID`),

 ) ENGINE=InnoDB AUTO_INCREMENT=22199955 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
4

1 回答 1

1

参考

如果不带参数调用,则返回 UNIX 时间戳(自 '1970-01-01 00:00:00' UTC 以来的秒数)作为无符号整数。如果使用日期参数调用 UNIX_TIMESTAMP(),它会返回参数的值作为自 '1970-01-01 00:00:00' UTC 以来的秒数。date 可以是 DATE 字符串、DATETIME 字符串、TIMESTAMP 或格式为 YYMMDD 或 YYYYMMDD 的数字。

mysql> SELECT UNIX_TIMESTAMP();
+---------------------------------------------------------+
| UNIX_TIMESTAMP()                                        |
+---------------------------------------------------------+
| 882226357                                               |
+---------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT UNIX_TIMESTAMP('1997-10-04 22:23:00');
+---------------------------------------------------------+
| UNIX_TIMESTAMP('1997-10-04 22:23:00')                   |
+---------------------------------------------------------+
| 875996580                                               |
+---------------------------------------------------------+
1 row in set (0.00 sec)
于 2013-10-01T11:24:05.303 回答