Is there an easy / built-in way to find relevant concept from a given one? [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
Based on
keywords extracted from URLs
a given keyword
I would like to find the most relevant keywords where the relevance score will be calculated by looking up how many times a random keyword has been extracted from the same URL that the given one
As an example:
I'm providing Soccer keyword which has been extracted from 100 URLs
From those 100 URLs, I have also extrated Argentina 80 times and France 75 times
=> I would then have (Soccer, Argentina) = 0.8 & (Soccer, France) = 0.75
I'm using a relational database, PostgreSQL, where I created 2 tables URL & Keywords.
Database schema
I can easily, from a given keyword, get all the URLs where the keyword has been extracted.
From those URLs I can retrieve all other keywords and "count/group by" them to further determine the relevance score:
SELECT SCE1.keyword, count(*) as count from Keywords SCE1
LEFT JOIN Keywords SCE2 ON SCE1.URL_id = SCE2.URL_id
WHERE SCE2.keyword ='Arsenal Football Club'
GROUP BY SCE1.keyword
ORDER BY count DESC
What is a better way to do that in PostgreSQL?

Related

Relational algebra operations [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm stuck with relational algebra.
I mean, how can I express functions like "SUM(), COUNT()," etc in RA?
Thanks, any help will be kindly appreciated
To start, you simply have to know that SUM and COUNT are called aggregate functions. Then, just google "relational algebra for aggregate functions".
I don't know how to subscript/superscript on Stack Overflow, but this wikipedia entry has an example at the end of the paragraph. (You'll see GMax(Balance)(Account).)
Also promising: go to this link, and search the page for "Aggregate"... you'll see Fsum(salary)(E) with subscripts.
something like this?
SQLFiddle example
what cannot you understand? be more specific please.
You can find more details in your DBMS documentation
Or visit the wiki
Basically aggregate functions will make some kind of "cumulative" operation over a set of rows and usidng one column to (SUM, AVERAGE, etc) based on one or more "key" columns.
Example: You have a dataset containing demographic data from all cities of the nation, it happens to have a population count and a region identity column. You can use it to create a report of total population by region.

Rearrange the characters in a string alphabetically using SQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am looking to take a string field and rearrange the characters into alphabetical order. For example, if it was a name field and the name was MICHAEL SMITH it would change to ACEHHIILMMST.
The main purpose is to look for duplicates in a field like name where someone could have made a typo and put in the name as MICHEAL SMITH or MICHAEL SMTIH. Another option I thought of would be to assign a number value to each letter (1-26) and then if the sum of those values and the length of the name field are the same it would be considered a duplicate. Problem with that is I do not know how to sum up numbers in a string field.
Also, I am using Oracle SQL so the functions would be based on those available.
Any ideas or at least places to start?
EDIT
I am not trying to ask for the code for how to do this, I am asking more if it is possible or not and if possible, what would my starting place be (types of functions, techniques, etc)
Check utl_match. It can be used to measure the similarity of two strings.
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHEAL SMITH') from dual
85
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHELLE SMITH') from dual
79
select utl_match.edit_distance_similarity('MICHAEL SMITH','FRANKIE JONES') from dual
8

Display endless amount of data in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
If I have an endless amount of data, can I display all of it in sql?
I know there is obviously select *, but then it will never complete.
Is there a command for this?
You can use TOP to select subset of total records
SELECT TOP 100 * from table
This selects top 100 records.
By using Order By clause , you can specify the basis on which subset of records is returned.
Now if you are asking about limits of Sql Server database management system then please see this link - Maximum Capacity Specification of Sql Server
Eg
Max Databases per instance of SQL Server ( both 32 bit and 64 bit ) = 32,767
Usually, you will prefer to use some kind of paging, since you cannot actually show "endless amount of data" in user-friendly way on application.

To write a query where it would extract the number of requests on various fields . [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want write a query which would give two columns :
1> Type of Query 2> Count
This result set should have following structure
Here the 1st column values should be predefined and the count has to
be calculated . I want to check the Request column of source table and
find specific pattern . If that pattern is found increase the count .
For Example :
If there is a word "greenhopper" found in the request column then that
belongs to type GREENHOPPER .
OR
If there is a word "gadgets" found it is of the type DASHBOARD . and
so on ...
So I want to analyze the usage of various categories by using the log
table .
Hence Finally I can get the amount of usage and after that I can build
a pie chart out of it .
SELECT 'Greenhopper' AS TypeOfQuery, COUNT(*) AS Cnt
FROM YourTable
WHERE Request LIKE '%Greenhopper%'
UNION ALL
SELECT 'Dashboard', COUNT(*)
FROM YourTable
WHERE Request LIKE '%gadgets%'
-- And so forth
You said they were predefined right? So you'd have ~10 different statements UNION'd together.
WITH Requests AS
(
SELECT
CASE
WHEN Request LIKE '%Greenhopper%' THEN 'GreenHopper'
WHEN Request LIKE '%gadgets%' THEN 'Gadgets'
-- and so on
ELSE 'Misc'
END RequestType
FROM YourTable
)
SELECT
RequestType,
COUNT(*) RequesCount
FROM Requests
GROUP BY RequestType
;
No data to test but I believe this approach will perform better as the table will be scanned less times. Performance is never going to be ideal though because of the LIKE and first wild card. This will prevent seeks.
Further explanation of why LIKE does not perform here
Having just re looked at the question you may be able to improve performance further by changing the search string so it only has a wildcard on the right
e.g. LIKE 'GET /rest/gadget%' and so on.

Fulltext index query - illogical [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a fulltext index on my table but am getting weird results...
Think a table of current Toys... (huggle buddy is "hot" apparently at the moment)
If a I search for Huggle on my table the results brought up are "Huggle Buddy" toys and I get 12 results...thats fine, perfect.
But if I search for "Huggle Buddy" I get almost 500 results, which is ok as i know its searching both words and combinations, but, the items with Huggle Buddy in the title do not appear first, how do i fix that? e.g. Is there an order by scoring?
Put the search term in quotes so it will only search for an exact match. You'll only get results that contain the exact match "Huggle Buddy".