MySQL - SQl to select top 5 from each group in n groups using access 2003

Asked By Cherifa Hima
18-Jul-11 01:01 PM
Hi,

I have a table of data : affiliate, lenders, pub rate, sales rate, and leads. I want to find top 5 from each affilialte ordered by the leads. I want to use SQL language.
for example:


Affilate Lenders Pub rate sale rate leads
Chima A1 2 3 4
Chima A2 3 2 5
Chima A3 4 3 4
Chima A18 19 18 28
Chima A19 20 19 30
Barm b1 21 20 32
Barm b2 22 21 34
Scarese C3 37 36 64
Scarese C4 38 37 66
Scarese C5 39 38 68
Scarese C6 40 39 70
Scarese C7 41 40 72
  SRIRAM E replied to Cherifa Hima
18-Jul-11 02:43 PM
Hi Use This Query for your requirement

select affiliate, lenders, pubrate, salesrate,leads from TableName 
Where leads in (select top 5 Leads from TableName t1 where t1.Affilate=Affilate order by t1.Leads)



try and let me know if you have any issues
  Cherifa Hima replied to SRIRAM E
18-Jul-11 03:22 PM
Hi,

When I replaced TableName with Table 1, I receied this message : Syntax error in from clause.
  Devil Scorpio replied to Cherifa Hima
18-Jul-11 05:06 PM
Hi Cherifa,

Please try this query to find top 5 from each affilialte ordered by the leads.

I tried it, its working fine.

suppose the Tablename is Table1

SELECT affiliate, lenders, [pub rate],[sale rate],leads
FROM Table1
WHERE [Pub rate] IN (
    SELECT TOP 5  [pub rate]
    FROM Table1 as S
    WHERE S.affiliate = Table1.affiliate
    ORDER BY leads DESC
);
Create New Account
help
Compound INSERT SELECT FROM WHERE subquery problem MySQL -> SQL Server 2005 conversion SQL Server , SQL, Server, 2005, conversion" / > This SQL language is nuts, just nuts. How does anybody put up with such a crude scripting macro language? First, I found out that the curly ' (apostrophe) is not the same as the straight apostrope. Then I'm trying to convert a MySQL data statement into a MS SQL Server 2005 data statement (see below), but keep getting
dates SQL Server i have this sql in a web page: mySQL = "INSERT INTO precos (ano, nm_mes, n_semana, cod_casa, inicio, fim, preco)" mysql = mysql & " values (" & datepart("yyyy", dt_inic) & ", " mysql = mysql & datepart("m", dt_inic) & ", " mysql = mysql & n_semana & ", " mysql = mysql & request("cod_casa") & ", convert(datetime, '" mysql = mysql & request.form("inicio") & "'), convert(datetime
Tell me difference between Sql & Mysql Tell what is the difference Sql & mysql in more understandable form. hi, follow the below link to compare SQL & MySql www.tometasoftware.com / files / MySQLvsSQLServer.doc regards, gopinath g. hi, here is the content present in the link : http: / / www.tometasoftware.com / files / MySQLvsSQLServer.doc MySQL vs. SQL Server When considering a utility for data management the two most popular choices are MySQL
difference between mysql and sql server end of post MySQL vs. SQL Server When considering a utility for data management the two most popular choices are MySQL and SQL Server. Both are efficient at keeping your data organized and readily available through a user the air about the most common question asked in data management discussions: "Which is better, MySQL or SQL Server?" Some key questions to ask yourself in determining which data management tool is best
Large MySQL SQL File -> ASP.NET Database SQL Server , ASP.NET, Database" / > Greetings, I have backed up a MySQL database from a PHP site. This backup is in the form of a large (55MB) SQL file. Can anyone tell me how I can convert it to a SQL Server Express database suitable for use with ASP.NET? The file is too large for cut and paste and it appears the SQL content is not fully compatible with Microsoft SQL. Thanks. Jonathan SQL Server New Users Discussions SQL Server (1) MySQL (1) ADO.NET (1