Selecting/Ranking Top Items

Oct 27, 2007

Hello,

I have a question about writing an SQL query than can run in Access and/or MS SQL Server.

I have a table with the following fields (amongst others):

City
Store
SalesDollars

There are 10 cities, with each city containing 100+ stores, each with a SalesDollars numeric value.

1) How do I write a SELECT statement that will return the top 50 stores from each city (500 in total) ?

2) How do I create a field that is the ranking of all these stores in descending order by SalesDollars (1-500)?

Thank you in advance for your help!

Sam

View 7 Replies


ADVERTISEMENT

Selecting All Items In A Recursive Relationship

Feb 21, 2007

Hello

I'm having trouble writing a query that references a join to a table with a recursive relationship in a SQL Server 2005 database.

I have a list of products in Table1.
Each product belongs to a Category.
Categories are stored in Table2 which has a self-referencing relationship that forms a hierarchical list of categories and sub-categories.
Like so...
||-ID-||-Name-||-Parent-||
||1 ||Cat1-----||Null-----||
||2 ||Cat2-----||Null-----||
||3 ||Cat3-----||1-------||
||4 ||Cat4-----||1-------||
||5 ||Cat5-----||2-------||
||6 ||Cat6-----||2-------||
||7 ||Cat7-----||3-------||

What I'm trying to do is write a sproc that will pull down all products that belong to a particular category or any of it's sub-categories.

I managed to write a sproc that could handle two levels of category by using union to join two queries together but I don't know how to handle an n-tier hierarchical structure.

Can you point me in the right direction?

Many Thanks

View 2 Replies View Related

Summing Invoice Items - The Multi-part Identifier Items.TAX Could Not Be Bound

Apr 17, 2007

Hi: I'm try to create a stored procedure where I sum the amounts in an invoice and then store that summed amount in the Invoice record.  My attempts at this have been me with the error "The multi-part identifier "items.TAX" could not be bound"Any help at correcting my procedure would be greatly appreciate. Regards,Roger Swetnam  ALTER PROCEDURE [dbo].[UpdateInvoiceSummary]    @Invoice_ID intAS    DECLARE @Amount intBEGIN    SELECT     Invoice_ID, SUM(Rate * Quantity) AS Amount, SUM(PST) AS TAX    FROM         InvoiceItems AS items    GROUP BY Invoice_ID    HAVING      (Invoice_ID = @Invoice_ID)    Update Invoices SET Amount = items.Amount    WHERE Invoice_ID =@Invoice_IDEND

View 3 Replies View Related

SQL Server 2012 :: Identify Sets That Have Same Items (where Set ID And Items In Same Table)

Feb 25, 2015

I am struggling to come up with a set-based solution for this problem (i.e. that doesn't involve loops/cursors) ..A table contains items (identified by an ItemCode) and the set they belong to (identified by a SetId). Here is some sample data:

SetIdItemCode
1A
1B
24
28
26
310
312
410

[code]....

You can see that there are some sets that have the same members:

- 1 and 10
- 2 and 11
- 7, 8 & 9

What I want to do is identify the sets that have the same members, by giving them the same ID in another column called UniqueSetId.

View 8 Replies View Related

Reporting Services :: Group And Sum Items / Sub-items Into One Record

Apr 10, 2015

I'm having an issue creating a report that can group & sum similar items together (I know in some ways, the requirement doesn't make sense, but it's what the client wants).

I have a table of items (i.e. products).  In some cases, items can be components of another item (called "Kits").  In this scenario, we consider the kit itself, the "parent item" and the components within the kit are called "child items".  In our Items table, we have a field called "Parent_Item_Id".  Records for Child Items contain the Item Id of the parent.  So a sample of my database would be the following:

ItemId | Parent_Item_Id | Name | QuantityAvailable
----------------------------------------
1 | NULL | Kit A | 10
2 | 1 | Item 1 | 2
3 | 1 | Item 2 | 3
4 | NULL | Kit B | 4
5 | 4 | Item 3 | 21
6 | NULL | Item 4 | 100

Item's 2 & 3 are child items of "Kit A", Item 5 is a child item of "Kit B" and Item 6 is just a stand alone item.

So, in my report, the client wants to see the SUM of both the kit & its components in a single line, grouped by the parent item.  So an example of the report would be the following:

Name | Available Qty
--------------------------
Kit A | 15
Kit B | 25
Item 4 | 100

How I can setup my report to group properly?

View 6 Replies View Related

DELETE Items Where Count(items) &>1

May 12, 2006

I cannot find an easy way to DELETE items which are > 1 time in my table (i am working with MS SQL 2000)


idserialisOk
-------------------
2AAA1
3BBB0
5dfds0
6CCC1
7fdfd 0
8AAA0
9CCC0


I want to DELETE each Row IN



SELECT doublons.serial, Count(doublons.serial) AS 2Times
FROM doublons
GROUP BY doublons.serial
HAVING Count(doublons.serial)>1



and WHERE isOK = 0

in my exemple , after deleting, my table must look like



idserialisOk
-------------------
8AAA1
9CCC1
3BBB0
5dfds0
7fdfd0



thank you for helping

View 10 Replies View Related

Selecting The Most Recently Edited Item AND Selecting A Certain Type If Another Doesn't Exist

Sep 20, 2007

I've got a big problem that I'm trying to figure out:
I have an address table out-of-which I am trying to select mailing addresses for companies UNLESS a mailing address doesn't exist; then I want to select the physical addresses for that company. If I get multiple mailing or physical addresses returned I only want the most recently edited out of those.

I don't need this for an individual ID select, I need it applied to every record from the table.

My address table has some columns that look like:
[AddressID] [int]
[LocationID] [int]

[Type] [nvarchar](10)
[Address] [varchar](50)
[City] [varchar](50)
[State] [char](2)
[Zip] [varchar](5)
[AddDate] [datetime]
[EditDate] [datetime]

AddressID is a primary-key non-null column to the address table and the LocationID is a foreign key value from a seperate Companies table.
So there will be multiple addresses to one LocationID, but each address will have it's own AddressID.

How can I do this efficiently with perfomance in mind???

Thank you in advance for any and all replies...

View 2 Replies View Related

Ranking

Oct 22, 2007

I was wondering what kind of SQL statement I would need to do the following:For example I have a table that has an ID (vID) column, product id (vPID) and a timestamp (vTime). What I essentially want to do is go through this table and find the top 10 instances of any vPID. I will illsutrate it below.-      vID              vPID                vTime       1                25                  101012323       2                25                  101012323       3                09                  101012323       4                25                  101012323       5                25                  101012323       6                11                  101012323       7                25                  101012323       8                10                  101012323       9                10                  101012323       10               25                  101012323       11               25                  101012323       12               25                  101012323       13               25                  101012323       14               11                  101012323       15               25                  101012323Now what I want to do is return the top vPID instances from highest to lowest so my output should return 25, 11, 10 etc.I hope what I'm asking made sense to you guys, basically im just looking for the top 10 instances of a any product id (vPID) Thanks. 

View 3 Replies View Related

Need Help!! Ranking

Sep 28, 2000

Hello All,
I am working on a ranking scenario for a client and I am stumped. Here's the situation...I have an aggregated table that has number of items sold for a salesperson for a given pay period. My client wants to the top 10 salespeople in a report. If two sales people tie, then they should have the same rank, and then the next salesperson in the ranking should have the appropriate number in the sort order. I am trying to figure out how to accomplish with the rank column below.

SalespersonID AmountSold Rank
1 5 1
2 5 1
3 4 3
4 4 3
5 2 5

I need the data in my table to look like the example and I am having a difficult time figuring out how. Any help would be appreciated.

Thanks,
Terry

View 1 Replies View Related

Ranking

Jan 17, 2005

My small number of brain cells prohibits me from figuring this out. I've got a table

ProviderName EOPCodeTotalDenied
Memorial Hosp66$4,598
Memorial HospA3$2,133
Memorial Hosp22$1,111
Memorial Hosp20$912
Memorial Hosp39$4,321
Memorial Hospb2$62
Parkdate Hospb2$6,251
Parkdate Hosp66$2,346
Parkdate Hosp22$1,252
Parkdate Hosp20$4,056
Stone HospV33$8,059

I need to output this table as below (with a denial rank for each hospital -- DESC sort on TotalDenied).
I'm stuck on how to get the DenialRank column to work.

ProviderName EOPCodeTotalDeniedDenialRank
Memorial Hosp66$4,5981
Memorial Hosp39$4,3212
Memorial HospA3$2,1333
Memorial Hosp22$1,1114
Memorial Hosp20$9125
Memorial Hospb2$626
Parkdate Hospb2$6,2511
Parkdate Hosp20$4,0562
Parkdate Hosp66$2,3463
Parkdate Hosp22$1,2524
Stone HospV33$8,0591

Appreciate the help.

Ray

View 5 Replies View Related

Ranking

Feb 14, 2008

Hi guys
I'm trying to figure out how to rank records. From the highest value to the lowest. Can you please help?

View 3 Replies View Related

Ranking From 0

Mar 14, 2008



Hello all

Im working on a table in SQL server 2005 (sp2). A piece of that table is as below. I need a SQL code that adds a new column called rank that ranks starting from 0 by Tire_ID by date asc. For example, for Tire_ID = 41317 and 41350 the result will look like in the second table:

original:








Date
Tire_ID
Truck
Position
Area

10/5/1999 0:00
41317
T110
1
BAG

2/5/2000 0:00
41317
T109
1
BAG

5/9/2000 0:00
41317
T103
6
BAG

11/14/1999 0:00
41350
T109
2
BAG

4/19/2000 0:00
41350
T105
4
BAG

7/5/2000 0:00
41350
T104
4
BAG

9/3/2000 1:00
41350
T104
3
BAG

9/17/2000 1:00
41350
T115
5
BAG

Result( new)









Date
Tire_ID
Truck
Position
Area
rank

10/5/1999 0:00
41317
T110
1
BAG
0

2/5/2000 0:00
41317
T109
1
BAG
1

5/9/2000 0:00
41317
T103
6
BAG
2

11/14/1999 0:00
41350
T109
2
BAG
0

4/19/2000 0:00
41350
T105
4
BAG
1

7/5/2000 0:00
41350
T104
4
BAG
2

9/3/2000 1:00
41350
T104
3
BAG
3

9/17/2000 1:00
41350
T115
5
BAG
4

Thanks in advance

View 5 Replies View Related

Ranking With MDX

Oct 25, 2007



I have a sales report showing Customer, tons shipped, and sales amount with two parameters: year and month. I want to show the ranking by month by both tons and sales. It is easy enough to sort the results by one of the measures and compute a line number but I can't seem to get the rank function to work to compute the ranking by two different measures.

Any ideas?

Thanks.

View 1 Replies View Related

Ranking Within A Set

Oct 16, 2007



I have a table that has several dozen account numbers. In the same table, each account number has several thousand control numbers (apparently the person who designed the DB never heard of Dr. Codd).

Anyway, I want to get the last five created control numbers for each account number. I have a "CreatedDateTime" field that I can use to order the control numbers by creation. I can use the Top and Rank functions to get the last five for an individual account number but I cannot seem to produce a solution with the last five for each account number.

Anyone have any ideas?

Thanks.

View 3 Replies View Related

Search Ranking

Oct 24, 2007

I'm building a standard search function for this project im working on and I wanted to know how could I do the following; Basically want I am using the standard "LIKE" function to search keywords but I also want to rank the returns based on how many matches. For example if someone uses the keywords "dog run park fast" and I have a couple of records that have certain amount combinations with these words, how would I return the one that has the most combinations to the least. If one record had "dog, run,park", another has "dog run" and the last would have "fast". How would I being those results in that order.Thanks for any help. 

View 3 Replies View Related

Query For Ranking

Nov 23, 2004

The problem is :
I have table :
--------------------------------
...User ... Speed(minute)...
Maria 0.8
John 0.5
Alan 0.8
Anne 2.0
Smith 1.0
Kate 1.5
Evan 1.5
--------------------------------

---> I wanna set ranking for them such as:

Rank.....User.....Speed(minutes)
1 John 0.5
2 Maria 0.8
2 Alan 0.8
4 Smith 1.0
5 Kate 1.5
5 Evan 1.5
7 Anne 2.0
---------------------------------

Anyone can tell me how?
Thanks much

View 2 Replies View Related

Ranking Top 3 Records.

Jul 28, 2006

A few weeks ago i posted this and got it to work perfectly. Now im trying to retreive the '3' closest stores rather than just the '1' closest store. How would I go about doing this? I tried using 'TOP 3' in the subquery but you can only retrieve one value.

Here is the origonal post:

"I have a table containing 100 stores, 5000 customers, and the distance between each store and each customer. I am trying to build a query that simply lists each customer and which store is closest and its distance.

Right now it looks like this:
Customer1|store1|33
Customer1|store2|15
Customer1|store3|28
Customer1|store4|35

Customer2|store1|35
Customer2|store2|95
Customer2|store3|28
Customer2|store4|76

I want to get it like this:

Customer1|store2|15
Customer2|store3|28"



Here is the solution:


Code:

SELECT CustomerPost, StorePost, StoreName, Distance
FROM Customer_Store_Distance2 as T
WHERE (Distance =
(SELECT MIN(Distance)
FROM Customer_Store_Distance2
WHERE CustomerPost = T.CustomerPost))

View 10 Replies View Related

Ranking To 2 Decimal

Feb 14, 2005

I have query that calculate percentage. i need to rank it to nearest 2 decimal places

query like

SELECT distinct [table a]/[table b] *100 as percentage
from blabla


results
.........
2.7777
20.125


..
want to get result
3
20

View 4 Replies View Related

Ranking With Groupings

Sep 4, 2015

how I could achieve a ranking number, where I have some grouping involved.I want to have the groups in sets of 4, but if I get to a new person the ranking increases, even if I haven't filled the group. For example:

Name Year Sales Ranking
-------------------- ----------- ----------- --------------------
John Smith 2009 1296 1
John Smith 2010 1296 1
John Smith 2011 1296 1
John Smith 2012 1296 1
John Smith 2013 1296 2

[code]....

So, when I get to John's 5 year, the Rank increased. I then only had two more rows before I get to Nina, but the Rank number goes up, as the details are for a different person from the prior user.

Select *, DENSE_RANK() over (Order by Name) + ((RANK() over (Partition by Name Order by Year) - 1) /4) as Ranking
from #Test
Order by Name, Year

Drop Table #TestThis works for John, but Nina then has a Ranking of 2 for her only year, where as she should be 3. Steve also then has a value one too low for all of his ranks.

View 3 Replies View Related

Ranking Function

Dec 14, 2007

I have a rank column and a column with percents. The higher the percent the better the rank. How would I do this?

View 1 Replies View Related

Help With Ranking Or Row Count

Mar 20, 2008

I have tried to get answers on this before, but haven't had any luck. I am working on trying to finish a report using SSRS in Visual Studio.

The report is a Sales report. I have the report grouped by Location of our Offices and their Customers grouped underneath. The Customers revenue is Summed on the Customers group footer. I have this sorted by Top customer (highest revenue) to lowest customer (lowest revenue). This is fine and great, but now I need to limit the number of Customers (there could be upwards of 100 or more per Office) to the Top 20.

I would like to do this on the report side, but if I need to do it in my SQL query I will.

I would like to get the row number for the Customer group footer. Then I can limit these <=20, but when trying on the report side doing

=rownumber(Customer)

I get an aggregate function error for incorrect Scope.

Any help would definately be appreciated. I have been stuck for about a week now trying to figure this out.

View 4 Replies View Related

Ranking Results With SQL 2000

Jan 4, 2008

Hi everyone,I am interested in showing a ranking of each result that I get.  Basically, the results will be the time of a race along with their name.  However, what I want to do is also have a third column that will show their place.  I would like my result to be like this:Place    Name    Time 1        Bob        1:00.002        Bill        1:00.012        Rob        1:00.014        Jill        1:00.025        Jon        1:00.035        Joe        1:00.037        Jane        1:00.04  Records are constantly being added to the table, so the place must be calculated dynamically.  Now, I do realize that SQL 2005 has the wonderful RANK() OVER (ORDER BY [time]) AS [Place] feature, but unfortunately SQL 2000 does not have that mechanism.  What is the best way to display these results?  Should they be included calculated on the SQL side or using the datagridview control?  Any help would be greatly appreciated. Thanks,Jason 

View 2 Replies View Related

Sql 2000 Ranking With Sub Query

Jun 21, 2008

Hello,

I am having an issue with a SQL query I wrote in SQL 2000. I am almost there but am lacking in one area, hoping a better programmer than me and a fresh set of eyes can pick off my mistake.

The goal is very straight forward, order and rank the following fields:
R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference

The issue lies in my sub query in the AND / OR joins... This query will work if I sort and rank on two fields, but if I try three or more it does not work properly.

Here is my entire query:

SELECT

TOP 100 PERCENT

R1.AutoPoolID,
R1.PoolType,
R1.Week,
R1.Username,
R1.TieBreakerTotal,
R1.Wins,
R1.Losses,
R1.Ties,
R1.TBActual,
R1.TBDifference,
R1.WinPercentage,
R1.Points_Thursday,
R1.Points_Saturday,
R1.Points_Sunday,
R1.Points_Monday,
R1.Points_Total,

(
SELECT COUNT(*)
FROM tblWeeklyStandings_All R2
WHERE R2.AutoPoolID = R1.AutoPoolID AND R2.Week = R1.Week AND
(
R2.PSWins > R1.PSWins OR
R2.PSWins = R1.PSWins AND
R2.PSPoints_Total > R1.PSPoints_Total OR
R2.PSPoints_Total = R1.PSPoints_Total AND R2.PSTBDifference < R1.PSTBDifference
)
) + 1 AS Rank

FROM dbo.tblWeeklyStandings_All R1 INNER JOIN
dbo.qryUsers_SDR ON R1.AutoPoolID = dbo.qryUsers_SDR.AutoPoolID AND R1.PoolID = dbo.qryUsers_SDR.PoolID
WHERE
(R1.PoolType = '2007' OR R1.PoolType = '2008') AND
(dbo.qryUsers_SDR.OrderBy1 = '6') AND
(dbo.qryUsers_SDR.PointSpread = 1)

ORDER BY R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference

At this point I am ready to buy SQL 2005 because I think this gets easier, hoping a 2000 wiz can help me correct my error, or missing "(", or something!

Here are the results:
Rank Username Wins Points TB Difference
1. test 0618084 16 50 0
4. test 0618083 16 50 66
3. test 0618081 15 50 55
4. test 0618082 14 50 55
5. admin 2 0 0

As you can see the ranking is not correct. It should be the following:
Rank Username Wins Points TB Difference
1. test 0618084 16 50 0
2. test 0618083 16 50 66
3. test 0618081 15 50 55
4. test 0618082 14 50 55
5. admin 2 0 0

Sometimes it works sometimes it does not, frustrating!

In different scenerios, I am ranking the following way when ties occur. My code sometimes does this correctly but as you can see above it fails in certain areas, like it forgets R1.PSWins DESC, R1.PSPoints_Total DESC, R1.PSTBDifference....

Rank
1 Tied
1 Tied
3
4
5 Tied
5 Tied
5 Tied
8

etc...


The most frustrating thing is the sort order is correct, it is the rank sub query that fails under certain scenerious...

View 1 Replies View Related

Ranking A Derived Table?

Jul 30, 2013

I want to rank the below table by Sum [Pts} Desc AS Position?

,Sum(Games) as Pl
,SUM(Win) as W
,SUM(Draw) as D
,SUM(Loss) as L
,SUM(F) as F
,SUM(A) as A
,SUM(Total) as Tot
,ROUND(AVG(GPG),2) AS GPG

[code].....

View 2 Replies View Related

Matching Process With Ranking

Jan 9, 2007

Hi all,

I've recently tasked my self whereby I wish to rank the info off of a CV and then find matches for this information against a database containing job info, so I'm left with a list of jobs with their relevant perspective possible candidates. I'm thinking of importing the cv as text then manipulating it using Full_text ranking procedures.

Question is do people feel this is the best way of writing what is basically a matching process ?? Is there any 3rd party software out there which does this sort of thing already ??

Any assistance appreciated

View 1 Replies View Related

Help On A 'Spread' Kind Of Ranking...

Nov 9, 2007

Hi all,

Just can't figure this out. I'll try not to give a long-winded explanation (I hope), let's say this is the table, for example:
[Table1]
RowNumber | Value
1 | 4
2 | 6
3 | 3
4 |10
5 | 6
6 | 5
7 | 8
8 | 8
9 | 2
10 | 6

I want to write a query that creates a column whose values are similar to (ROW_NUMBER -1), and resets each time a value is present.
Using the above example, 6 will be the test value. So, I want to know how many rows it takes till 6 is repeated.

Output would be:
RowNumber | Value | Spread
1 | 4 | 1
2 | 6 | 0
3 | 3 | 1
4 |10 | 2
5 | 6 | 0
6 | 5 | 1
7 | 8 | 2
8 | 8 | 3
9 | 2 | 4
10 | 6 | 0

I think PARTITION BY can be used somewhere, with the ORDER BY on the [RowNumber] - but I'm just not sure on which ranking function to use, and how to reset the Ranking on the number 6 (above example).

Any help would be appreciated. This has been a mind-teaser for me, and I give

Thanks,
Denvas

View 5 Replies View Related

Implementing Ranking Position

Jan 17, 2007

Hello,

I have a group that is custom made on the table's grouping expression, something like

=SWITCH(Fields!Country.Value="Portugal",IIF(Fields!Storetype.Value="Frs","Portugal Frs", "Portugal"),

Fields!Country.Value="Italy","Italy",Fields!Country.Value="Spain","Spain",Fields!Country.Value="United States","United States",

Fields!Country.Value="Internet","Internet",Fields!Country.Value<>"","Other")

The thing is that i order this by my value, and then i use a column that is the rowcount, but sadly i got

11 Portugal

19 United States

30 Spain

How can i do this like

1 Portugal

2 US

3 Spain

Is there something like in C ++1 or something that increments a number depending on the line of the table that is in?

Thank you

View 1 Replies View Related

Ranking Equivalent In Sql Server 2000??

Sep 7, 2005

There are three columns I need to query and rank, then group and total. I'm using MS SQL server 2000 and it doesn’t have a ranking function like the newer SQL server and oracle has. Does anyone have a clever way to create or simulate a ranking function? Thanks so much!
Jake :confused:

View 1 Replies View Related

How Do I Create A Ranking Query In MSSQL

Feb 17, 2007

I need to use mssql to create a ranking of some kind. This is the situation:
I need to assign position to a list of students based on thier scores. e.g
Student Score Position
StudentA 56 4
StudentB 78 1
StudentC 66 2
StudentD 56 4

I need to create the positions based on the scores of the ctudents.
I will appreciate any assistance.
Thank you.

View 3 Replies View Related

Ranking Results On XML Node Search?

Nov 14, 2006

hi.

i know this is a bit of a shot in the dark but, does anybody know of a reasonably understandable way to rank XML node path results based on keyword search terms? seems like there are tons of uber-complex docs on the internet about this. i dont mind if it is a bit of a work-around, i am just looking for something that is reasonable non-complex that i can wrap my mind around. links etc apprecaited.

thanks.

View 1 Replies View Related

Ranking In SQL 2000 Query Analyzer

Oct 11, 2005

Hello-

I was wondering if someone could help me out. What would be the best way for me to go about determining the sale number from the following table:

applicantID calltime result
1 1/5/05 no sale
1 1/15/05 no sale
1 1/25/05 sale
1 1/26/05 no sale
12 1/5/05 no sale
12 1/15/05 no sale
12 1/16/05 no sale
12 1/25/05 sale
12 1/26/05 no sale

the resulting query would provide:
applicantID saleattempt
1 3
12 4

etc. Ultimately, I am trying to figure out how many attempts needed to make a sale.

Thank you...

ps

View 3 Replies View Related

Ranking Function Not Available In Reporting Services.

Aug 2, 2007

I have the problem.
I have many Cognos Reports to be converted in Reporting Services.
Out of which there are several Ranking Reports.
Cognos has inbuilt Rank Function while SSRS does not have.
I dont want to do grouping on Database level, rather trying to find a solution in RS.
But unfortunately I couldnt find any solution.
I sorted the group according to requirement, now only thing left is showing the rank number and limiting top 60 rows only.
I tried filters to show TopN, but always gives and error and also tried custom code to show the row number for that group but didn't work.

Anyone has any idea how to overcome this limitation of Reporting Services.
One more interesting is when I try to create a field in dataset having IIF and / within.. RS terminates, all unsaved work gone.
Sometimes I think Microsoft cannot have a product which is 100% perfact and working.

View 3 Replies View Related

Combining FREETEXTTABLE Rank With Another Ranking

Jul 26, 2007

I am using FREETEXTTABLE to enable users to search forum posts. It works extremely well (and fast!) and I am very happy with it.

I also have a top ten list of 'Most viewed' forum posts. Each time a post is accessed, a 'viewcount' value is incremented accordingly. The ten forum posts with the highest viewcount appear in the top ten list (by order of viewcount, of course).

Now... when a user searches on a search term, I would like the top ten list to also be affected by this search.

For example, the user searches on 'foo'. In response they get a list of results containing 'foo'.
However, the top ten list also changes to reflect this. It now shows the ten forum posts with the highest viewcount which also contain the word 'foo'.

This is easy enough to do. The problem arises when we also add proximity searches.


For example, if I search on 'foo bar', FREETEXTTABLE will look for records which have both or either of these words. Records which contain both words will be ranked higher than records which contain either word. And of the records which contain both words, the closer together the two words are, the higher the ranking will be.

But how does this now work with the top ten list? For example, I may have two records:

- Record A has been viewed 10 times. It contains the words 'foo' and 'bar' and they are next to each other.
- Record B has been viewed 10,000 times. But it only contains the word 'foo'.

Now, according to 'viewcount', record B should be ranked higher. But according to FREETEXTTABLE, record A should be ranked higher.

So, I need to combine both these rankings in some way. Regardless of how the 'top ten' records are chosen, they will be ordered by viewcount. But I'm not sure how to get the right top ten records in the first place.


Any thoughts would be much appreciated.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved