通过每行的时间戳匹配字段在子选择中检索结果

时间:2015-01-01 10:39:44

标签: mysql unix-timestamp

使用此查询我的目标是从子查询中的另一个表中检索数据,其中参数比较unixtime戳。但是我的第三个圆柱('有效')的结果仍然是空的?

SELECT COUNT( valid.call_id )FROM calls AS valid WHERE SECOND((
SELECT conf.cca_setvalidtime FROM user_conf AS conf        
WHERE MONTH(FROM_UNIXTIME(conf.activ_date)) = MONTH(FROM_UNIXTIME(valid.last_call ))        
    )) < SECOND( valid.call_duration )

) AS 'valid'
FROM calls
GROUP BY EXTRACT(
YEAR_MONTH FROM last_call ) 

1 个答案:

答案 0 :(得分:0)

对于任何需要类似东西的人来说,这是解决方案; - )

SELECT DATE_FORMAT( last_call, '%M' ) AS 'month', COUNT( call_id ) AS 'total', (

SELECT COUNT( valid.call_id )
FROM calls AS valid
WHERE TIME((


SELECT conf.cca_setvalidtime FROM user_conf AS conf        
WHERE EXTRACT(YEAR_MONTH FROM conf.activ_date ) = EXTRACT(YEAR_MONTH FROM valid.last_call ) AND conf.for_role=1



)) < TIME( valid.call_duration )
AND EXTRACT(
YEAR_MONTH FROM valid.last_call ) = EXTRACT(
YEAR_MONTH FROM calls.last_call )
) AS 'valid'
FROM calls
GROUP BY EXTRACT(
YEAR_MONTH FROM last_call )