SQL今天获取以及单行中的昨天记录

时间:2017-05-18 10:16:17

标签: mysql

我们有一个log表,其中包含以下列:job name,start time,end time, status,source count, target count,reject count,error count等。

每条记录将包含有关每项工作的信息。 我的结果应该是job name,start dt,end dt, status,source count, target count,reject count,error count(Today entry),source count, target count,reject count,error count(yesterday count)

我们需要记录今天和今天的记录数量。 我们目前正在使用以下查询获取记录。

select * from logtable where start dt=current_date

任何人都可以帮我用SQL来获得上述结果。

1 个答案:

答案 0 :(得分:0)

好的,基于您的更新的新anser:

echo my-trigger-name > /sys/class/leds/.../trigger

以上内容适合您。 你说这些列被命名为“开始时间”,但在选择中你使用“start dt”?

旧答案:

如果您只想要今天和昨天的两行在同一行上,您可以这样做:

select  logToday.`job name`,
        logToday.`start time`,
        logToday.`end time`, 
        logToday.status,
        logToday.`source count`,
        logToday.`target count`,
        logToday.`reject count`,
        logToday.`error count`,
        logYesterday.`source count`, 
        logYesterday.`target count`,
        logYesterday.`reject count`,
        logYesterday.`error count`
from logtable logToday
join logtable logYesterday on logYesterday.`start time` = subdate(current_date, 1)
where logToday.`start time` = current_date;

如果我错过了什么,请提供更多信息,我会修改答案。

相关问题