I have a question on a practice assignment that I can't solve. Can someone
help me out?
Question:
The table Arc(x,y) currently has the following tuples (note there are
duplicates): (1,2), (1,2), (2,3), (3,4), (3,4), (4,1), (4,1), (4,1), (4,2).
Compute the result of the query:
SELECT a1.x, a2.y, COUNT(*)
FROM Arc a1, Arc a2
WHERE a1.y = a2.x
GROUP BY a1.x, a2.y;
Which of the following tuples is in the result?
a) (2,3,2)
b) (2,4,6)
c) (4,2,6)
d) (3,2,6) 5 3340
KGuy wrote: I have a question on a practice assignment that I can't solve. Can someone help me out?
Yes, create the table in question to your database, insert the given
values to there and then execute the given query and check which of
given results matches to the actual result.
This task is so simple that you don't even need brains to solve it,
since all you have to do is follow the instructions, compare few rows
and tell what you see.
If you don't have database, you can get one for free, for example mysql: http://www.mysql.com/
> Yes, create the table in question to your database, insert the given values to there and then execute the given query and check which of given results matches to the actual result.
Of course, I could do that, but I would like to understand why the output is
what it is. Sorry if I was unclear. Thanks for the reply.
-Imran
KGuy wrote: Of course, I could do that
Don't say you could do that, just do it. When you tell the corrent
answer, someone might be able explain it. And if want to make a guess,
be sure not choose wrong one.
Please understand that if we just give the correct answers it would be
the same as just shooting you in the head. It would do you more harm
than good. Point of practise assignments is that you learn by doing them.
>I have a question on a practice assignment that I can't solve. Can someone help me out?
Thanks everybody. I managed to solve it by hand using tips from someone
(Andy Hassall). It takes a while, but at least it's doable and I understand
it. If the answer is important to you, reply to this post.
On Sun, 23 Jan 2005 13:00:20 -0500, KGuy wrote:
(crossposting removed) I have a question on a practice assignment that I can't solve. Can someone help me out?
Hi KGuy,
In a few weeks time, you'll have a test. If you don't learn to work out
your assignments now, you'll certainly fluke the test.
And if you're lucky and pass the test, you'll be in even more trouble when
you're hired and you have to debug some real SQL.
Question:
The table Arc(x,y) currently has the following tuples (note there are duplicates)
(snip)
If there are duplicates, you don't have a table at all. A collection of
data that may hold duplicates is a heap. I'm truly amazed that there are
still schools where SQL is taught with text books that don't include a
primary key on every table in every example or every assignment.
(1,2), (1,2), (2,3), (3,4), (3,4), (4,1), (4,1), (4,1), (4,2). Compute the result of the query:
SELECT a1.x, a2.y, COUNT(*) FROM Arc a1, Arc a2 WHERE a1.y = a2.x GROUP BY a1.x, a2.y;
Almost all professionals prefer the (more verbose, but better documenting)
infixed join notation. For outer join, the infixed notation is the only
way to avoid ambiguity. For inner joins, beth versions are allowed, but
the infixed notation is more popular. Also, avoiding the optional AS
between table name and table alias is not recommended either!
SELECT a1.x, a2.y, COUNT(*)
FROM Arc AS a1
INNER JOIN Arc AS a2
ON a1.y = a2.x
GROUP BY a1.x, a2.y;
This is how the query should (IMO) appear in a decent studybook.
Which of the following tuples is in the result?
a) (2,3,2) b) (2,4,6) c) (4,2,6) d) (3,2,6)
Easy to work out, actually. As an example, I'll show you why the answer
isn't a. You can then work out the three remaining options.
Each row in the output that shows 2 as the first value has a1.x=2. This
must stem from the row (2, 3), as that is the only row with an x value of
2. The join condition (a1.y=a2.x) means that the a2 row must have an x
value of 3 (as the y value in the a1 row is 3). Two rows qualify: (3, 4)
and (3, 4). Both have an y value of 4, so before grouping, there are 2
rows with a1.x=2 and a2.y=4. After grouping, this is 1 group with a row
count of 2. The result set should contain (2, 4, 2) as the only row
starting with 2.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: pauldepstein |
last post by:
I am reading Grimshaw and Ortega's "C++ and Numerical Methods." They
construct a vector class which contains the variable vec, a float*
variable where the length of the array (number of components in the
vector) is given by the variable name veclength.
That is what I _do_ understand. What I don't understand is the
coding for the...
|
by: DH |
last post by:
I have a VERY basic question about figuring database size. I've inherited a
database which is generally similar to this basic one:
Item, Red, Blue, Green, Yellow
(text), (int),(int),(int),(int)
box, 1,0,0,2
hat, 0,0,0,1
car, 3,0,0,0
This format leads to a lot of zeros in the rows which take up a lot of
|
by: Malcolm |
last post by:
After some days' hard work I am now the proud possessor of an ANSI C BASIC
interpreter.
The question is, how is it most useful?
At the moment I have a function
int basic(const char *script, FILE *in, FILE *out, FILE *err);
It returns 0 on success or -1 on fail.
|
by: Ramesh |
last post by:
hi,
Let me ask some basic questions.
Can anybody explain me about the following questions:
1. When we have to create sn key? Whenever we compiled
Component we have to create or it is a one time process?
2. What information contained in sn key. I gone through
that it is having public key. How it is using this key to
intract with client....
|
by: Pete |
last post by:
I'm cross posting from mscom.webservices.general as I have received no answer
there:
There has been a number of recent posts requesting how to satisfactorily
enable BASIC authorization at the HTTP level but as yet no fully useful
answer.
I too have been trying to call an apache/axis webservice which desires a
username/password from my C#...
| |
by: Aussie Rules |
last post by:
Hi,
Having a mental block on this one. Have done it before but can't rack my
brain on how...
I have an object, with a bunch on property, and I add that object to a combo
box. I want the property '.fulladdress' to be the value that appears in the
drop downs text section.
How to I set that parameter to be the one shown inthe drop down
|
by: MikeB |
last post by:
I've been all over the net with this question, I hope I've finally
found a group where I can ask about Visual Basic 2005.
I'm at uni and we're working with Visual Basic 2005. I have some books,
- Programming Visual Basic by Balena (MS Press) and
- Visual Basic 2005 by Willis (WROX),
but they don't go into the forms design aspects and...
|
by: frankhanretty |
last post by:
Do I have to install Visual basic on the remote terminals as I did on the server?
I have an visual basic 5 application running fine on my client's server and he is now networked. He wants to run the visual basic applicaton that runs on his server on the remote terminals. (he has two networked to his server) My question is do I now have to install...
|
by: Chris Asaipillai |
last post by:
Hi there
My compay has a number of Visual Basic 6 applications which are front endeed onto
either SQL Server or Microsoft Access databases.
Now we are in process of planning to re-write these applications into Visual Basic.Net.
My managers main thought is that Visual Basic 6 is (or has!) stopped being supported
by Microsoft.
|
by: Scott Stark |
last post by:
Hello,
I'm trying to get a better handle on OOP programming principles in VB.NET.
Forgive me if this question is sort of basic, but here's what I want to do.
I have a collection of Employee objects that I can iterate through
relatively easily. I've included code at the bottom of this message.
I can pretty easily iterate through my...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |