Count single instance in subset of data - business-objects

Good morning all. I am working in Business Objects and am building essentially a history table and am having an issue summarizing it. A sample of Data is below.
Region Ref# Level
East 1 0
East 1 1
East 1 2
East 2 0
West 3 0
West 3 1
What I want the output to be is below (Crosstable):
Level 0 1 2
East 1 - 1
West - 1 -

Related

Using a three column unique combination in SQL only once

So, I'm managing a table where it's stored the scores of a particular competition.
The table looks like this:
ENTRY_ID TEAM_ID DATE PLACE SCORE
1 1 2021-10-12 Ireland 64
2 2 2021-10-12 Ireland 31
3 3 2021-10-12 France 137
4 2 2021-10-12 France 61
5 5 2021-10-12 France 38
6 1 2021-10-12 France 66
7 2 2021-10-12 Italy 17
8 3 2021-10-12 Italy 61
9 1 2021-10-12 Italy 74
The competition is held at three different places at the same time, with technically all teams being able to have teams in all of them.
Each team however can only win one point so, in the example, it's possible to see that Team 1 would win both in Italy and Ireland, but it should be awarded only one point for the highest score, so only Italy. The point in Ireland should go to the second place.
The query I was trying to get the results is:
SELECT `TEAM_ID`, `PLACE`
FROM `COMPETITION`
WHERE `date` = "2021-10-12"
GROUP BY `PLACE`
ORDER BY `SCORE` DESC, `id` ASC
LIMIT 3
So I could retrieve all three winners with no further processing.
The results I'm trying to achieve should repeat neither the TEAM_ID nor PLACE, in this particular example it should output:
3 FRANCE (Since it has the highest score in France at 137)
1 ITALY (For the highest score in Italy at 74)
2 IRELAND (For the second-highest score in Ireland, since Team 1 already won in Italy)
The production model of this table has far more entries so it's unlikely there would be any clashes with too many second-places.
How can I achieve that?

Have column display group's value

I have an SSRS report that pulls data similar to the one in the below table
incident_type zone seconds data_category data_type
Alarm East 30 A 1
Alarm East 90 A 2
Alarm East 120 B 1
Alarm East 180 C 1
Alarm West 30 A 1
Alarm West 90 A 2
Alarm West 120 B 1
Alarm West 180 C 1
Warning East 30 A 1
Warning East 90 A 2
Warning East 120 B 1
Warning East 180 C 1
Warning West 30 A 1
Warning West 90 A 2
Warning West 120 B 1
Warning West 180 C 1
What I want to do is display it like so:
Alarm East West
A 1 30 30
A 2 90 90
B 1 120 120
C 1 180 180
Warning East West
A 1 30 30
A 2 90 90
B 1 120 120
C 1 180 180
So, I set up my Tablix with the following groups
As you can see I have the data grouped in a way that breaks the data up correctly. However, the resulting tables look like this
Alarm East West
A 1 30 30
A 2 90 90
B 1 120 120
C 1 180 180
Alarm East West
A 1 30 30
A 2 90 90
B 1 120 120
C 1 180 180
As you can see, "Alarm" is repeated for the header. How can I get the value for [incident_type] to be the correct value in relation to the group?
It seems incident_type group is not set to be a header group.
Delete incident_type group and right click data_category group, select Add Group / Parent Group.... A window will pop up, set Add group header and select incident_type field.
After that, a new column will be added to the beginning of your tablix, delete that column and the required rows to leave this:
Merge the first two cells in the first row for the incident_type and you will get the desired output.
Let me know if this helps.

How can I find a hierarchy from a closure table in MYSQL if I have a list of names within the hierarchy?

Fiddle: http://sqlfiddle.com/#!9/c1495/1
I have a table named "locations":
id name parent
1 Sweden 0
2 England 0
3 Stockholm 1
4 Vasteras 1
5 Town 3
6 Town 4
7 London 2
8 Town 7
And table named "closure":
parent child depth
1 1 0
1 3 1
1 4 1
1 5 2
1 6 2
2 2 0
2 7 1
2 8 2
3 3 0
3 5 1
4 4 0
4 6 1
5 5 0
6 6 0
7 7 0
7 8 1
8 8 0
Now I'd like to convert a hierarchy of names I have on hand into location IDs.
Example: Sweden => Stockholm => Town would yield:
id name parent
1 Sweden 0
3 Stockholm 1
5 Town 3
How could I do this without also returning any of the places named "town", but where the parents aren't exactly the same?

SQLite COUNT and selecting from multiple tables

Consider the database (made up for example):
Table 'owner'
id name
1 john
2 andrew
3 peter
Table 'duck'
id name ownerID
1 duck1 1
2 duck2 1
3 duck3 1
4 duck4 2
5 duck5 2
6 duck6 3
7 duck7 3
8 duck8 1
9 duck9 3
10 duck10 3
11 duck11 1
12 duck12 2
Table 'food'
id name type duckID
1 beef meat 4
2 grass veg 8
3 lemon fruit 5
4 apple fruit 3
5 pizza snack 7
I wish to write some SQL that for each OWNER, COUNT the number of ducks which eat some kind of food. For example for owner John, there would be 2 ducks (ducks 3 and 8).
So far I am writing this code:
select owner.name, count(duck.ownerID)
from duck, food, owner
where duck.id == food.duckID
and duck.ownerID == owner.id;
I am getting the result:
Peter | 5
Any suggestions are appreciated.
This is done with an group by clause:
select owner.name, food.name, count(duck.id)
from duck, food, owner
where duck.id == food.duckID
and duck.ownerID == owner.id
group by owner.name, food.name;
This query gives you one row for each combination of owner name and food name with the number of the owner's ducks eating this food.

I need sql query for getting the Required format

i am having table Category with the columns like
id(AutoIncrement),Parent_id,Level,Name
initially for level 1 datas has Parent_id is 0. autoincrement id will be Parent_id for next levels .my table table table datas will bw like this
id Parent_id Level Name
1 0 1 Indian
2 0 1 International
3 0 1 Nri
4 1 2 BC
5 2 2 Christian
6 2 2 Muslim
7 4 3 MBC-1
8 7 4 OBC-2
9 1 2 FC
i want to show records in this format (its like a tree view)
id Parent_id Level Name
1 0 1 Indian
4 1 2 BC
7 4 3 MBC-1
8 7 4 OBC-2
9 1 2 FC
5 2 2 Christian
6 2 2 Muslim
2 0 1 International
3 0 1 Nri
4 1 2 BC
Can any one should help me to get this arrangement of datas using sql Query?
If it does not have a set number of branches you likely want to loop over a query in your app or write an SP to obtain all nodes. Some good reading here:
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/