Jump to content

Mysql --Sql Experts Help Plz


Recommended Posts

Posted

mama,,sql lo chinna help kavali


i have a table with 26 rows and 2 columns. firts column is a string and second column is a number. i need the output as follows.

top 10 based on column 2 (sum) (group by column1) and after the top 10 results i need the other 16 values aggregated(sum of column2) with the name 'OTHERS'.
the result should be like this:

column1 column2
a 146
b 120
c 100
d 92
..
.
.
.
.others 256

oracle ,db2 aithe with clause vadite aiyipodi,kani mysql does not support with clause..so need ur advice

Posted

[b]This gets top 10 sum[/b]

SELECT top 10, SUM(column2)
FROM table
GROUP BY column1

[b]get all other than first 10[/b]

select sum(column2)
FROM table
where column1 not in(select top 10 column1 from table)
GROUP BY column1

Posted

[quote name='macha' timestamp='1358450175' post='1303125245']
[b]This gets top 10 sum[/b]

SELECT top 10, SUM(column2)
FROM table
GROUP BY column1

[b]get all other than first 10[/b]

select sum(column2)
FROM table
where column1 not in(select top 10 column1 from table)
GROUP BY column1
[/quote]


my sql lo top 10 panicheyadu. we have to use LIMIT. limit anedi sub query lo panicheyadu..

Posted

[quote name='macha' timestamp='1358450175' post='1303125245']
[b]This gets top 10 sum[/b]

SELECT top 10, SUM(column2)
FROM table
GROUP BY column1

[b]get all other than first 10[/b]

select sum(column2)
FROM table
where column1 not in(select top 10 column1 from table)
GROUP BY column1
[/quote]


//////////////
SELECT top 10, SUM(column2)
FROM table
GROUP BY column1
///////////////////////

top pakkana comma unte error ostadi mama..... n e query crrt res raadu..... adi frst grp by chesi andulo top 10 teesukuntadi...
akkada req top 10 lo grp by cheyyaaliiii....

try this..




SELECT sum(column2), column1
FROM (select top 10 * from table)a
group by column1

Posted

http://stackoverflow.com/questions/1598700/mysql-sum-group-by

http://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-sum-with-group-by.php

http://stackoverflow.com/questions/3320863/get-sum-in-group-by-with-join-using-mysql

for ranking your items use DESC or ASC as reqd

Posted

http://stackoverflow.com/questions/1274482/mysql-sum-when-using-group-by-not-working

Posted

[img]http://www.desigifs.com/sites/default/files/Suneel%20%287%29.gif?1289984060[/img]

×
×
  • Create New...