Question

Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid,...

Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid, childid, edgeweight, graphid), formulate a SQL statement for each query in the following.

2. Assume each node has a different weight, return the nodeids of the top three nodes that have the highest weight for the graph with graphid = 1234.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SQL Query return the node ids of the top three nodes that have the highest weight for the graph with graphid = 1234.

SELECT nodeid FROM
    (
    SELECT *
     FROM Nodes
    where graphid = 1234 
    ORDER BY nodeweight desc
    )
WHERE rownum <= 3
ORDER BY nodeweight ;

Explanation

First we get all the information of the Nodes where graphid=1234 then sort them according to node weight in descending order .

Now from the above output we extract node ids of first 3 rows by using rownum .

Hence we get Output as Top Three ids as the final result

So this is how you can get the needed data in SQL

Thank You

Do Upvote the answer if u like it and have any doubt ask in comment

Add a comment
Know the answer?
Add Answer to:
Consider the following three tables where keys are underlined: Graphs(graphid, graphname), Nodes(nodeid, nodename, nodeweight, graphid), Edges(parentid,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT