sql server - Select Max Limit 1 from Group -


i'm making in webpage cache system. wanted make simple page rank system along output. problem is, want display recordset highest relevance score per unique domain. 1 domain may have multiple records different titles, descriptions, etc. problem is, instead of getting 1 recordset containing unique domain, groups recordsets of unique domain , outputs them all. want recordset highest relevance score per unique domain per group before outputs next (and different domain highest relevance group)

select title, html, sum(relevance)   (   select title, html, 10 relevance page title ‘%about%’ union   select title, html, 7 relevance page html ‘%about%’ union   select title, html, 5 relevance page keywords ‘%about%’ union   select title, html, 2 relevance page description ‘%about%’   ) results group title, html order relevance desc; 

i'm getting:

domain1 title html domain1 title html domain1 title html domain2 title html domain2 title html domain2 title html 

what want

domain1 title html domain2 title html domain3 title html domain4 title html domain5 title html 

i'm not sure why code works, since think should have

 order sum(relevance) desc 

instead of

 order relevance desc 

maybe that's problem?

beyond that, this. ugly, work. better if sql server understood how refer aliases later in query. alas.

 select title, html, case when title '%about%' 10 else 0 end + case when html '%about%' 7 else 0 end + case when keywords '%about%' 5 else 0 end + case when description '%about%' 2 else 0 end relevance page case when title '%about%' 10 else 0 end + case when html '%about%' 7 else 0 end + case when keywords '%about%' 5 else 0 end + case when description '%about%' 2 else 0 end > 0 order case when title '%about%' 10 else 0 end + case when html '%about%' 7 else 0 end + case when keywords '%about%' 5 else 0 end + case when description '%about%' 2 else 0 end desc; 

or maybe slight rearrangement:

 select title, html, relevance (select title, html, case when title '%about%' 10 else 0 end + case when html '%about%' 7 else 0 end + case when keywords '%about%' 5 else 0 end + case when description '%about%' 2 else 0 end relevance page) relevance > 0 order relevance desc; 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -