2016-04-25 23 views
-1

选择数据我有一个的freeradius-MySQL查询以选择acctstarttime是超过30天数据:其中日期时间是30天以内

下面

是查询:

SELECT SUM(acctinputoctets - 
      GREATEST((30 - UNIX_TIMESTAMP(acctstarttime)), 0)) + 
     SUM(acctoutputoctets - 
      GREATEST((30 - UNIX_TIMESTAMP(acctstarttime)), 0)) 
    FROM radacct 
WHERE username = 'user2' 
    AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > 30 

我会喜欢有一个相同的性质查询选择数据,其中acctstarttime是少于30天和即时通讯困难时间。

任何人都可以帮忙吗?

+0

您正在使用哪种类型的数据库?我猜MySQL,但你能确认吗? –

+0

如果可能的话添加样本数据表 –

+0

是的我正在使用mysql。 accctstarttime的值与“2016-04-24 06:20:45” –

回答

0

试试这个:

SELECT acctstarttime 
FROM radacct 
WHERE acctstarttime < ADDDATE(acctstarttime, INTERVAL 30 DAY) 

欲了解更多信息和功能:Date and Time Functions