2011-12-20 4 views
0

두 개의 테이블이 있습니다. 가격, code_one 다른 테이블의 값을 기준으로 그룹화

  • 두 번째 테이블이있다 : code_one,
  • code_two 두 테이블 code_one 테이블을 사용하여 결합 할 수

    • 첫 번째 테이블은 열을 가지고있다.

      "가격 합계를 code_two로 그룹화하는 방법"은 무엇입니까?

      내가 시도 :

      Select sum(price) from table1 Group By (select a.code_two from table2 a, table1 b where a.code_one = b.code_one) 
      
    +0

    @OMG 조랑말을 : 나는별로 그룹화 한 후 하위 쿼리를 가지고 시도 ... 같은 뭔가 : 그룹 작성자 (A, 표 1 표 2에서 a.code_two 선택 b 여기서 b.code_one = a.code_two) – Nik

    답변

    1
    select code_two, SUM(price) 
    from table1 t1 INNER JOIN table2 t2 ON t1.code_one = t2.code_one 
    group by code_two 
    
    +0

    table1에 where 조건이 있으면 어떨까요? 날짜 필드를 말하는 것과 같습니다. 그래서 저는 특정 날짜에만 원합니다. 다음은 정확합니까? select code_two, SUM (price) from table1 t1 INNER JOIN table2 t2 ON t1.code_one = t2.code_one 여기서 t1.date = 'somedate'group by code_two ??? – Nik

    +0

    네일이 말한대로 올바른 – Nighil

    +0

    입니다. 맞습니다. – Zohaib

    0
    select sum(price) 'Price' from firsttable inner join secondtable on firsttable.code_one = secondtable.code_one 
    group by secondtable.code_two 
    
    관련 문제