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.
6. Return all graphids of those graphs that have some fork nodes but no join nodes.
I can't say this question is incomplete because here I know what I have to create 3 tables and tables have attributes and everything is mentioned just one simple problem is that you haven't mentioned anything about the data that needs to be inserted into the table so that based on that I can write the SQL statement but yeah now this is up to me so I will insert data so that it matches with the question and I can formulate SQL statement.
-------------
Graphs Table
create table Graphs(
`graphid` int not null primary key,
`graphname` varchar(20)
);
Nodes Table
create table Nodes(
`nodeid` int not null primary key,
`nodename` varchar(20) not null,
`nodeweight` int not null,
`graphid` int not null,
foreign key(graphid) references Graphs(graphid)
);
Edges Table
create table Edges(
`parentid` int not null,
`childid` int not null,
`edgeweight` int not null,
`graphid` int not null,
primary key(parentid,childid),
foreign key(graphid) references Graphs(graphid)
);
Now the Values that I have added into the tables
Graphs Table
insert into `Graphs`(`graphid`,`graphname`) values
(1,'X'),
(2,'Y'),
(3,'Z');
Nodes Table
insert into `Nodes`(`nodeid`,`nodename`,`nodeweight`,`graphid`)
values
(101,'first',10,1),
(102,'fork',20,2),
(103,'join',30,3),
(104,'second',15,1),
(105,'join',5,3);
Edges Table
insert into `Edges`(`parentid`,`childid`,`edgeweight`,`graphid`)
values
(102,11,20,1);
Now the query to get all graphics of the graph which have fork nodes but no join nodes
as you cam I have inserted some values in the nodes table with node name as fork,join,first and so on and now we need to fetch value which don't have join nodes and just fork nodes
select graphid from Nodes where nodename ='fork';
This query will return the graphid whose nodename is a fork and nothing else
select graphid from Nodes where nodename not in
('join');
but this query will return all the graphid except the one with nodename join
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. 9. Return all graphids of those graphs such that every entry node is also a fork node.
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. 8. Return all graphids of those graphs such that every edge has a different weight.
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. 5. Return all graphids of those graphs in which every node is the child of all other nodes.
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. 1. Return the graphids of those graphs in which every exit node has a different weight.
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. 7. Return all graphids of those graphs such that the graph has at least 1 node that is not connected to any other nodes (i.e. neither as a parent nor as a child).
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. 3. Suppose there is a node X in graph with graphid = 1234 such that all other nodes are the parents of node X. Return the nodeid of node X.
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.