答案 0 :(得分:1)
以下只是一个例子,你需要计算出分开的日期和时间。时间列作为一个单独的问题。
MySQL 5.6架构设置:
CREATE TABLE Table1
(`date` date, `time` time, `permanent_token` varchar(8), `RID` int, `SID` int)
;
INSERT INTO Table1
(`date`, `time`, `permanent_token`, `RID`, `SID`)
VALUES
('2015-08-04 00:00:00', '12:40:41', 'HPC12334', 12, 34),
('2015-08-04 00:00:00', '15:15:15', 'HPC12334', 18, 37),
('2015-08-04 00:00:00', '08:09:10', 'ABX2334', 48, 47)
;
查询1 :
select t.*
from table1 as t
inner join (
select permanent_token, `date` , MIN(`time`) as minTime
from table1
group by permanent_token, `date`
) as gby on t.permanent_token = gby.permanent_token
and t.`date` = gby.`date`
and t.`time` = gby.minTime
<强> Results 强>:
| date | time | permanent_token | RID | SID |
|--------------------------|---------------------------|-----------------|-----|-----|
| August, 04 2015 00:00:00 | January, 01 1970 12:40:41 | HPC12334 | 12 | 34 |
| August, 04 2015 00:00:00 | January, 01 1970 08:09:10 | ABX2334 | 48 | 47 |
答案 1 :(得分:0)
您可以尝试以下操作:
select DISTINCT(permenent_token),othercolumnname from tablename order by permenent_token desc
答案 2 :(得分:0)
使用Mysql distinct 关键字
编辑:
SELECT * FROM table GROUP BY permanent_token;
答案 3 :(得分:0)
$sql = "select DISTINCT(coloumn_name) from tablename";