2013-10-01 72 views
-1

查詢1爲什麼查詢得到0行

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; 
+2

查詢是不同的 - 他們在不同的範圍(08-01 VS 08-31),並與不同類型的 –

+0

PLZ expalin操作,其中錯在這裏 –

+1

你可以張貼表中創建報表,以及一些示例數據,理想作爲一個SQLFiddle? –

回答

1

Reference

如果被叫不帶參數,返回一個UNIX時間戳(秒因爲 '1970-01-01 00:00:00' UTC)作爲無符號整數。如果使用date參數調用UNIX_TIMESTAMP(),則它會返回自1970年1月1日「1970-01-01 00:00:00」以來秒數的值。日期可以是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) 
+0

我的問題是爲什麼第一個查詢不給結果 –

+0

後http://sqlfiddle.com/ –

相關問題