I want to have a SQL result look like this (match result query):
ID Arena Winner Loser Winner_score Loser_score
-----------------------------------------------------------------
1 1 Johnny Mark 16 8
2 2 Andrew Luke 16 7
Here are my tables (simplified)
Player_tbl
ID Player
-------------
1 Johnny
2 Mark
3 Andrew
4 Luke
Match_tbl
ID Match Arena
----------------------
1 Match 1 1
2 Match 2 2
Match_results_tbl
ID Match player_id player_score
-----------------------------------------
1 Match 1 1 16
2 Match 1 2 8
1 Match 2 3 16
2 Match 2 4 7
I am wondering how to structure my query to have the desired result.
Ok, I figured out my own issue. 1st, the match_results must be put in a table with a different structure, and 2nd, the inner sql query needed to be adjusted to pull from the proper database tables.
I have the following table:
Transaction Id
Authorizer
1
john
1
robert
2
Jane
2
Paul
And the result table I need is like this:
Transaction Id
Authorizer_1
Authorizer_2
1
john
Robert
2
Jane
Paul
How can i make this in Teradata SQL assistant?
Thanks in advance!
I am trying to update (middle name - mname) a database table based on a certain condition. SQLfiddle. http://www.sqlfiddle.com/#!9/3c022/2
I would like to know HENRY {null} FORD is belonging to one of other HENRY {A,B} FORD based on the coauthors and update the table.
The author with null middle name is updated with the middle name of the author with the same first and last name and with whom he has more number of common co-authors.
For example, based on the data the results is:
HENRY FORD HENRY FORD ---> this should be updated 'B' due to more common authors
HENRY A FORD HENRY A FORD
HENRY B FORD HENRY B FORD
However,
JACK SMITH JACK SMITH ---> this shouldn't be updated due to no common authors
JACK A SMITH JACK A SMITH
JACK B SMITH JACK B SMITH
Any suggestions are appreciate.
I have a table:
id owner ex_id
1 jack -
2 joe -
3 charlie 1
4 bill 3
5 helen 2
6 jack 5
7 anna 4
8 Kurt 7
It is possible to have in a select sentence (not a program, just sql) something like "get all the ex_id´s from id 7":
id 7: anna, bill, charlie, jack
(7 point to 4, 4 point to 3, 3 point to 1, 1 dont have property so it ends)
TIA
It is not possible to perform such a hierarchical query using pure SQL in MySQL, sorry to say.
Oracle can do it. http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm But that's not what you asked.
I have a dataset which shows a worker’s scores on various skills using four test types along with their supervisor and the director above the supervisor. To save space, the dataset example below is for just one worker. This is what I start with:
Director Supervisor Worker Test Skill Score
Doris Smith Jane Awe Lorina Marc Overall 1: Identifying Support 1
Doris Smith Jane Awe Lorina Marc Test A 1: Identifying Support 4
Doris Smith Jane Awe Lorina Marc Test B 1: Identifying Support 1
Doris Smith Jane Awe Lorina Marc Test C 1: Identifying Support 5
Doris Smith Jane Awe Lorina Marc Overall 2: Tracking the Sequence 3
Doris Smith Jane Awe Lorina Marc Test A 2: Tracking the Sequence 2
Doris Smith Jane Awe Lorina Marc Test B 2: Tracking the Sequence 5
Doris Smith Jane Awe Lorina Marc Test C 2: Tracking the Sequence 5
Doris Smith Jane Awe Lorina Marc Overall 3: Searching for Exceptions 3
Doris Smith Jane Awe Lorina Marc Test A 3: Searching for Exceptions 3
Doris Smith Jane Awe Lorina Marc Test B 3: Searching for Exceptions 3
Doris Smith Jane Awe Lorina Marc Test C 3: Searching for Exceptions 3
I feed this into SQL Server Reporting Services using either table wizard or matrix wizard. I have to move Skill column over the Score column so the skills are now columns.
Row Groups: Director, Supervisor, Worker Test
Column Group: Skill
Value: Score
I get this:
Director Suprviser Worker Test 1: Identifying Support 2: Tracking the Sequence 3: Searching for Exceptions
Doris Smith Jane Awe Lorina Marc Overal 1 3 3
Test A 4 2 3
Test B 1 5 3
Test C 5 5 3
Al Vega Overal 5 5 3
Test A 3 3 2
Test B 2 4 4
Test C 5 2 5
David Osorio Overal 1 1 3
Test A 2 4 2
Test B 4 5 1
Test C 2 3 2
Katie Lewis Ally McIntosh Overal 1 2 3
Test A 5 3 4
Test B 3 3 2
Test C 1 3 2
Christina Gooderd Overal 2 2 1
Test A 4 4 1
Test B 5 5 4
Test C 2 5 4
I need to have a value in each cell, so the values need to repeat for each group. So, what I want should look like this:
Director Suprviser Worker Test 1: Identifying Support 2: Tracking the Sequence 3: Searching for Exceptions
Doris Smith Jane Awe Lorina Marc Overal 1 3 3
Doris Smith Jane Awe Lorina Marc Test A 4 2 3
Doris Smith Jane Awe Lorina Marc Test B 1 5 3
Doris Smith Jane Awe Lorina Marc Test C 5 5 3
Doris Smith Jane Awe Al Vega Overal 5 5 3
Doris Smith Jane Awe Al Vega Test A 3 3 2
Doris Smith Jane Awe Al Vega Test B 2 4 4
Doris Smith Jane Awe Al Vega Test C 5 2 5
Doris Smith Jane Awe David Osorio Overal 1 1 3
Doris Smith Jane Awe David Osorio Test A 2 4 2
Doris Smith Jane Awe David Osorio Test B 4 5 1
Doris Smith Jane Awe David Osorio Test C 2 3 2
Doris Smith Katie Lewis Ally McIntosh Overal 1 2 3
Doris Smith Katie Lewis Ally McIntosh Test A 5 3 4
Doris Smith Katie Lewis Ally McIntosh Test B 3 3 2
Doris Smith Katie Lewis Ally McIntosh Test C 1 3 2
Doris Smith Katie Lewis Christina Gooderd Overal 2 2 1
Doris Smith Katie Lewis Christina Gooderd Test A 4 4 1
Doris Smith Katie Lewis Christina Gooderd Test B 5 5 4
Doris Smith Katie Lewis Christina Gooderd Test C 2 5 4
What do I fix/change/modify so I can have a value in each cell filled in?
As you've seen, SSRS treats row header cells differently, i.e. stretching them over any child groups.
Your report probably looks a bit like this:
I've highlighted the dotted lines that separate the report areas. This example report has the same issue as your example:
To get around this, the various row group values need to be moved from the row header area to the main report area.
First, delete the left four rows - when prompted choose Delete columns only.
You should only have the Skill column remaining.
Right click and Insert Column -> Outside Group - Left.
Keep adding columns using Insert Column - Left.
Once you have enough new columns, add the various grouping values. The report should look something like this:
Note that there are now no dotted lines between the Skill column and the Test column.
Now the group values are repeated for each row as required:
I had a similar issue, but in a matrix, needed to repeat prior value at the details group level when there is only one rowgroup. To do this, I used custom code.
For example, I have a column in my matrix named "Clusters". The row group field is a simple date field. In my data set, I have Date, Clusters, ResourceType as fields. I have different resource type values and so I can see the dates that clusters associated with a given resource type have data. My challenge came from the fact that my data set is sparse - for a given ResourceType value, not all dates have values. In my matrix, I ended up with rows that have blank values in cells that there is no corresponding row in the underlying data set. The use of Previous doesn't work well (lots of other examples).
To solve the problem, I used custom code and a hashtable as follows:
Private LastSeenValue as System.Collections.HashTable = New System.Collections.HashTable
' GetRowValue is used to fill in blank cells in the dynamic matrix with the nearest value above them in the same column.
' The data can contain multiple sets according to ResourceType field, and not all dates are present in all of these sets.
' This has the effect on the screen of having blank cells for each given date where there is no corresponding resource type.
' The requirement this function enables is that it allows filling in the blank cells with the nearest real value above.
' The SSRS PreviousRow function does not do this.
' Author: DanRo, 1/8/2016
'
' Some behavior notes for developers who follow and seek to alter the function.
' The prototype for the GetRowValue function performs "null to zero" coercion as a result of return type. This was done purposefully.
' The Object type for the FieldVal inpute parameter allows null rows to be processed with the same type of coercion
' on the incoming side.
' This is report specific logic that takes advantage of the fact that all of data requiring this function is numeric.
Function GetRowValue(ByVal FieldName as String, ByVal FieldVal as Object, ByVal ResourceType as String) As Double
' TheKey variable allows this function to be used for any number of columns for any number of resource types.
Dim TheKey as String
TheKey = "[" & FieldName & "][" & ResourceType & "]"
' See if a value was passed. In SSRS, when the cell tries to render in the matrix, there
' is no underlying data row for the column region, so a null (Nothing) gets passed by the runtime environment.
If FieldVal is Nothing Then
' Coercion on the return type happens when the HashTable Item property returns Null if the lookup fails.
' If the lookup succeeds, the last value encountered (top to bottom) will be present.
Return LastSeenValue(TheKey)
End If
' now we know that a value was passed
If (Not LastSeenValue.ContainsKey(TheKey)) Then
LastSeenValue.Add(TheKey, FieldVal)
Return FieldVal
End If
' A value was passed and we have an old value. Update it
LastSeenValue(TheKey) = FieldVal
Return FieldVal
End Function
Finally, in the Matrix Cell for Clusters column I set the expression to:
=Code.GetRowValue("Clusters", Fields!Clusters.Value, ReportItems!ResourceType.Value)
And that solved the problem. An added benefit is now my rows at the start of the table that were blank now correctly contain zeroes (which was correct for me). One tricky thing was Typing the FieldVal argument to Object instead of Integer (which was my Clusters data type) because you cannot check for existence on value types. Another was referring to the ReportItem!ResourceType.Value instead of Fields!ResourceType.Value because ResourceType was my column grouping. Finally, the return type choice for the function will impact whether your data has decimal points - so the choice of Double lets you handle both integers and real numbers. This would have to be modified to make this function handle strings correctly.
Before, Original Experience:
After, Values are now repeating where previously blank: