Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

joining same table without a common field

$
0
0

Oracle 11g/SQLPLUS

Given single table TABLE with three fields ID, PARM, VALUE, I want to select and group by based on different values of VALUE

E.g.

ID   PARM   VALUE

id1 accnt France-1    
id2 model Type-1    
id3 field blah    
id4 accnt France-2    
id5 model Type-1    
id6 field blah    
id7 accnt France-2    
id8 model Type-2    
id9 field blah    
id10 accnt Germany-1    
id11 model Type-1    
id12 field blah    
id13 accnt Germany-2    
id14 model Type-1    
id15 field blah

I want to count the number of models by substr(accnt)

German Type-1   2    
France Type-1   2    
France Type-2   1

I have something like this but I don’t know how to JOIN T1 and T2 as there is no common field.

select substr(T1.value, 1, 6), T2.value, count(*)
from Table T1, Table T2
where T1.parm='accnt'
and T2.parm='model'
group by substr(T1.value, 1, 6), T2.value

Viewing all articles
Browse latest Browse all 717

Trending Articles