-5

TABLE1

ID    |     DATE  
 a    |   10-06-2012    |   
 b    |   07-07-2012    |   
 c    |   10-06-2012    |   

TABLE2

ID    |  COST  |  
 a    |   3    |  
 b    |   4    |  
 c    |   4    | 

I have two tables and I would like to search the DATE e.g. 10-06-2012 and return the total COST for that DATE being 7.

ID is common in both tables.

4

1 回答 1

2

加入表,并使用sum聚合来添加值:

select sum(t2.COST)
from TABLE1 as t1
inner join TABLE2 as t2 on t2.ID = t1.ID
where t1.DATE = '10-06-2012'
于 2012-07-30T00:03:56.933 回答