0

我有 2 张桌子。

事务(id、resourceid、时间戳)

资源(ID,名称)

我想获得类似( resource.name,day,count(transaction.id) )的输出

我正在使用以下查询

select  EXTRACT(DAY from timestamp), resourceid, count(id) from transactions
where timestamp between '01-OCT-13' AND '10-OCT-13'
and resourceid in (select id from resource)
group by resourceid, EXTRACT(DAY from timestamp) \
order by EXTRACT(DAY from timestamp);

输出:

1,1,13
1,3,45
1,6,76
2,1,14
2,2,46

我想看到像这样的输出

1,resource1,13
1,resource3,45
1,resource6,76
2,resource1,14
2,resource2,46

有人可以帮帮我吗?

编辑

resource1 只是举例。我不想在数字 1 之前连接资源。我想要与 id=1 关联的实际名称。

4

1 回答 1

1

如果您加入事务和资源表,那么您可以使用 recurce.name 字段。这可能看起来像这样:

select  EXTRACT(DAY from timestamp), resource.name, count(transactions.id) 
from transactions inner join resource 
    on transactions.resourceid = resource.id
where timestamp between '01-OCT-13' AND '10-OCT-13'
group by resource.name, EXTRACT(DAY from timestamp)
order by EXTRACT(DAY from timestamp);
于 2013-10-30T23:59:26.073 回答