Jump to content

Group By Use Chesi Elaaa


Recommended Posts

Posted

Table lo data ila undi baa

col1 col2
1 abc
2 xyz
3 abc


o/p ila ravali ante query ela rayali

col1 col2 col3
1 abc 2
2 xyz 1
3 abc 2

here col3 is mtnhg but aggregation of col2

GROUP BY use chesi above mention chesinatlu o/p ela tevali (wht should be the query look like) :4_12_13:

  • Replies 68
  • Created
  • Last Reply

Top Posters In This Topic

  • qwerty1204

    16

  • chandrabhai6

    10

  • ChampakDas

    8

  • kiss4amiss

    6

Top Posters In This Topic

Posted

[quote name='arey ooo samba' timestamp='1343251419' post='1302200082']
Table lo data ila undi baa

col1 col2
1 abc
2 xyz
3 abc


o/p ila ravali ante query ela rayali

col1 col2 col3
1 abc 2
2 xyz 1
3 abc 2

here col3 is mtnhg but aggregation of col2

GROUP BY use chesi above mention chesinatlu o/p ela tevali (wht should be the query look like) :4_12_13:
[/quote]


what do you mean by aggregation??...do you need how many of the abc are there in table2 ?? or if there 2 or 3 u need the count...


Do you need count or distinct or something else.....PLz be clear exactly what you need to see.

Posted

select col1, col2, count(*) from table
group by col1,col2

Posted

Select
col1 ,
col2,
(select count(1) from tableX A where A.col2=B.col2 group by col2)
From TableX B

Posted

[quote name='Jeedeelu' timestamp='1343252711' post='1302200234']
select col1, col2, count(*) from table
group by col1,col2
[/quote]
Idi wrong bayya

Posted

[color=#00008B][background=transparent]SELECT[/background][/color][background=transparent] col1[/background][background=transparent],[/background][background=transparent] col2[/background][background=transparent],[/background][background=transparent] col3[/background][background=transparent]=[/background][background=transparent]count [/background][background=transparent]( * )[/background]
[color=#00008B][background=transparent]INTO[/background][/color][background=transparent] holdkey
[/background][color=#00008B][background=transparent]FROM[/background][/color][background=transparent] t1
[/background][color=#00008B][background=transparent]GROUP[/background][/color][background=transparent] [/background][color=#00008B][background=transparent]BY[/background][/color][background=transparent] col1[/background][background=transparent],[/background][background=transparent] col2
[/background][color=#00008B][background=transparent]HAVING[/background][/color][background=transparent] count [/background][background=transparent]( * )[/background][background=transparent] [/background][background=transparent]>[/background][background=transparent] [/background][color=#800000][background=transparent]1[/background][/color]

Posted

ila try chey, not sure


select distinct a.col1, a.col2, b.col3 from table1 a,
(select col2, count(*) as col3 from table1
group by col2) b
where a.col2= b.col2

Posted

[quote name='Thurum_Kaan' timestamp='1343252946' post='1302200266']
[color=#00008B][background=transparent]select[/background][/color]
[background=transparent] col1[/background][background=transparent],[/background][background=transparent] col2[/background]
[color=#00008B][background=transparent]from[/background][/color]
[background=transparent] [/background][color=#00008B][background=transparent]table[/background][/color]
[color=#00008B][background=transparent]GROUP[/background][/color][background=transparent] [/background][color=#00008B][background=transparent]BY[/background][/color]
[background=transparent] col12[/background][background=transparent],[/background][background=transparent] col2[/background]
[color=#00008B][background=transparent]HAVING count(*)>1[/background][/color]
[/quote]


idhi correct anukunta...

Posted

Try mine sure shot working


[img]http://www.gifsoup.com/view1/1444039/brahmi-hug-o.gif[/img]

Posted

[quote name='chandrabhai6' timestamp='1343252939' post='1302200265']
Idi wrong bayya
[/quote]

oops...ippude choosa..

Posted

[quote name='Thurum_Kaan' timestamp='1343252946' post='1302200266']
[color=#00008B][background=transparent]SELECT[/background][/color][background=transparent] col1[/background][background=transparent],[/background][background=transparent] col2[/background][background=transparent],[/background][background=transparent] col3[/background][background=transparent]=[/background][background=transparent]count [/background][background=transparent]( * )[/background]
[color=#00008B][background=transparent]INTO[/background][/color][background=transparent] holdkey
[/background][color=#00008B][background=transparent]FROM[/background][/color][background=transparent] t1
[/background][color=#00008B][background=transparent]GROUP[/background][/color][background=transparent] [/background][color=#00008B][background=transparent]BY[/background][/color][background=transparent] col1[/background][background=transparent],[/background][background=transparent] col2
[/background][color=#00008B][background=transparent]HAVING[/background][/color][background=transparent] count [/background][background=transparent]( * )[/background][background=transparent] [/background][background=transparent]>[/background][background=transparent] [/background][color=#800000][background=transparent]1[/background][/color]
[/quote]

Wrong

Posted

[quote name='ReddyGaru' timestamp='1343252693' post='1302200230']


what do you mean by aggregation??...do you need how many of the abc are there in table2 ?? or if there 2 or 3 u need the count...


Do you need count or distinct or something else.....PLz be clear exactly what you need to see.
[/quote]

basically in my col3 I need to know how many times the value of col2 is repeated in the entire table baa

×
×
  • Create New...