473,395 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to compare several rows in one table???

Hi:

I am a table holding football match results using DB2

ID = matchid
HN = Home team name
HID = Home team id
AN = Away team name
ANID = Away Team id
Eevent= use 1 for score, 2 for substitution, 3 for booking, 4 for Foul
Teamid = Which team performed "Event (1--->4)"
Date = Match Date
Expand|Select|Wrap|Line Numbers
  1.                                   Table  "Data"
  2. -------------------------------------------------------------------------------------------------
  3. ID     HN    HID    AN        ANID        Event           TEAMID     DATE
  4. 11111   a      5      b         3          1                 3    15/08/2007
  5. 11111   a       5      b         3          4                 5    15/08/2007
  6. 11111   a       5      b         3          1                 5    15/08/2007
  7.  
  8.  
  9. 22222   c      7      d         4          1                 4    11/08/2007
  10. 22222   c      7      d         4          1                 7    11/08/2007
  11. 22222   c      7      d         4          1                 7    11/08/2007
  12. ________________________________________________________
  13.  
What I want it display is :

ID = matchid
HN = Home team name
Hgoal = Home team Scores
AN = Away team name
Agoal = Away team scorses
( Because team 5 did a own goal (event = 4), the score is 2:1 )
Date = Match Date
Expand|Select|Wrap|Line Numbers
  1.                                          Table "Result"
  2.  
  3. -----------------------------------------------------------------------------------------
  4. ID     HN        Hgoal       AN    Agoal       DATE
  5. 11111   a         1          b       2         15/08/2007
  6. 22222   c         2          d       1         11/08/2007
  7. ___________________________________________________
  8.  

I tried use self join, however, still cannot do it, any one PLEASE PLEAE HELP!!!


Cheers

(Really sorry about the format, i tried to make to more readable)
Sep 6 '07 #1
1 1705
Remi
9
Hello :

Try to use a function as decode or case when to translate the event and group it for match id.
Sep 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
2
by: codejockey | last post by:
I have a simple project that requires I take a set of data from an Excel spreadsheet, compare it to a table in SQL Server (where column names match), and if there are changes in the Excel sheet,...
0
by: codejockey | last post by:
Please forgive the repost, but I'm trying to avoid the hack I want to implement since I cant get this sample to work. Can anyone help? *********************** William: Thanks for the reply. I...
9
by: VMI | last post by:
I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
1
by: chungiemo | last post by:
Hi thought I would do another thread as this one is a bit different from the previous problem I am looking for a solution to the relating problem Comparing 2 access databases with 2 tables,...
0
by: Gabe | last post by:
I'm completely new to SQL and this puzzle is over my head. Any advice would be greatly appreciated. Table: Visits Columns: RecNo VisitNo EnterDate LeaveDate...
5
by: chazzy69 | last post by:
Ok heres what im trying to achive i am constantly updating the information in a table but know i what know if the data im replacing it with is new, i.e. whether or not i already had the data in the...
2
by: site | last post by:
Have to compare dates of two rows in one table Input table COL1| COL2| COL3| COL4 1| A| 1-Jan-07| 6-Feb-08 2| A| 7-Feb-08| 31-Mar-08 3| A| 1-Jan-09| NULL SQL code to compare COL 4 date (Row...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.