Getting top 5 highest numbers from across multiple columns - mysql

I have a table as follows and I am trying to make a query and obtain the top 5 numbers across all the pay columns and the associated name to that number.
I am using Java and I could derive the data by selecting them all and get the information.
Intention is to loop through them, store first 5 numbers in an array and keep updating the array if the next number is higher than that ones present in the array. Which means looping through the array each time to check against the new number.
Is there a more efficient way and I could do everything in MySQL query itself?
Table Image
Expected results would be:
1200 Simon
1150 jenny
1000 alan
900 james
800 alan

Related

How to count a range of values in datastudio

I am trying to transform a report that I have made in sheets into the newest datastudio tool. In my sheet, I have a table where there are several columns that holds data related (this is because each row could have more than one value so I used the "split text into columns" function to represent).
What I have is something similar to:
ID
Component
Component 1
Component 2
101
wood
metal
gold
102
metal
copper
103
wood
gold
metal
In my excel, I have a formula to count the time a certain component is shown by using =COUNTIF(<range>,<string>)
Therefore, with the above formula, I have something similar to:
Component
count
wood
2
metal
3
copper
1
gold
2
I want to be able to build the same in datastudio. Turns out that since the components are divided into columns, I can only use one dimension and the result only shows the count of the first column.
I want to know if there is an easy way to accomplish this. My original data source is like this:
ID
Component
101
wood;metal;gold
102
meta;copper
103
wood;gold;metal
Maybe it's easier to work directly with the previous format but again, using the component in this case only counts for the first occurrence and not across the whole string.
For now, the only solution I can think of is splitting the text into rows instead of columns, but that is not feasible achievable using Google Sheets, or at least not that I am aware of.
Could somebody have an idea of how to accomplish this?
Thanks!
Edit
I am adding here the minimal reproducible example. This is the spreadsheet that I have (example) and the current report I am using so far (built-in sheets):
Now, I want to have the same report (plus more things) using datastudio. This is the report example I have in data studio. As you will see the record count for components is not accurate in DataStudio.
Here is a preliminary answer. I'll polish if we like it and delete it otherwise.
Consider the following sheet:
Range A2:B4 contains my data of interest. Rows 7:10 show the results I think you are looking for. The mechanism for creating this is the value of cell A6 which contains:
=ARRAYFORMULA(QUERY(FLATTEN(SPLIT(B2:B4,";")), "SELECT Col1, COUNT(Col1) WHERE Col1 is not null GROUP BY Col1"))
At the highest level, the formula splits each of the delimited text items into their own cell and then flattens all these cells into one column against which we then run a SQL query against the sheet to group and count them.

Dynamically generated SSRS reports

Is it possible to dynamically create SSRS tablix? I have a pretty complex requirement.
I have created tables in which I fill "metadata" for reports, i.e.:
column names
row names
row/column levels (parent/child)
font colours
font sizes
valid from/valid to attributes
translations
Then, I generate queries from this metadata, and join them on fact tables. So each query returns data as it should.
I generate data in levels, so you always know, in which level you're currently. So, you get data in the following form (I can change it, if that would ease creating of reports):
Row Text | Level 1 Text | Level 2 Text | Level 3 Text | Level 4 Text | Level 5 Text | Value
Basically, SSRS doesn't have to sum anything, it just shows the data. But here's where I get into trouble. I don't know, how to achieve a normal-looking report.
I have made 5 column groups (5 is the highest number of levels in any report), and every one is a child to previous one. Row groups get hidden based on the max level of current query, so if the query only has data on level 1, only 1 row is shown.
But here comes the tricky part. I have a report, that has data like this:
If some data is on level 5, and some on level 1 (others everywhere in between), the data on level 1 has 4 empty rows...
So, my report shows a lot of empty cells. Either that, or I show the same text for all 5 levels. Is there a smart way to address this issue? I can even change the whole concept, as I'm still early in development.
EDIT:
Here is one of the exact reports that has to be generated dynamically (it's a public template):
ssrs template

splitting the column fields into new columns in mysql

I need some help with some basic, i suppose, mysql.
given three columns such as the ones below:
[Events Counts Date
play 2 2017/06/05
pause 3 2017/06/05
first quartile 4 2017/06/05
play 10 2017/06/06
pause 12 2017/06/06][1]
How can I split the column event into new columns such Play column, pause columns and so on, having each of these new columns the relative data coming from the initial table?
Below you can find the link of what the resulting table should be looking like
Thanks

Fuzzy lookup in SSIS does not output the result expected

To make things simple lets say I have a Client table with Fields:
ClientID
PCode
Region
I have a look up Region table with Fields:
ID
PostCode
Region
The Client table has one row :
123, 3075, THOMASTOWN
The Region has 2 rows:
1,3074,THOMASTOWN
2,3075,LALOR
I am trying to cleanse some data using SSIS fuzzy lookup.
I use the Client as source and the lookup as Reference. When the Max number of matches to output per lookup is 1 the result is 123,3075,THOMASTOWN, 1,3074,THOMASTOWN. In this case SSIS prefers the value of region over the value of pcode. But when I increase this option to a higher (2, 4, or 100) all the result rows are the same as the previous one.
I expect when I increase the number the other row of the lookup table shows up as one of the matches because the row has the same region code as the Client row.
To my surprise when for the first time I increased the option from 2 to 4 I saw the expected result (the other lookup record as a match) in 2 out of 4 rows of the fuzzy lookup output but since then it has never happened again and I always see the exactly same records as per different values of Max number of matches option.
Can anyone explain to me what's happening here and if I am doing something wrong?
From BOL: http://msdn.microsoft.com/en-us/library/ms137786.aspx
The transformation returns zero or more matches up to the number of matches specified.
Specifying a maximum number of matches does not guarantee that the transformation
returns the maximum number of matches; it only guarantees that the transformation
returns at most that number of matches.
If you are using these two columns in your matching, the region seems to be different enough that the pcode is still not a strong enough match on its own to return any results.
There are a couple of options:
Try tuning the similarity threshold and see if you can get the row returned
Use two fuzzy lookups (one for each column), so that if the first does not match or the similarity % is not strong enough, you can perform a second lookup to make the match.

vb.net compare two table, insert the result into new table

I have two identical table which consist of 3 field: ID, TID, and ITEM..
ID acts as primary key, TID identifies group of ITEM. Each TID could have different number of ITEM.
i want to compare the 2 identical table with condition like
check each grouped ITEM by TID in table 1 to each grouped ITEM by TID in table2
if table1. grouped Item exist as much as N in table2, it will be inserted into new table by query INSERT SELECT
for example at the screenshot, C - F -A has 3 occurences in table 2, thus they will be inserted into new table..
could it be done using mysql query?
i've already tried this using program by populating the two table into two 2d array, comparing them and with simple IF CLAUSE, getting the desired results.. and it worked well..
but the problem is, when i'm using huge database, it take ridiculous time to complete..
when i'm comparing 1st 2d array(table1 with 2k records) and 2nd array (table2 with 870 records), it take 2 hours to complete!!
this is the actual database
and this one is what i've already tried, populating two table above into 2d array.. while assigning both 2d arrays with table records, i also include the IF CLAUSE to check if element of 1st 2d array has N occurences in 2nd 2d arrays, the INSERT SELECT query will be executed..
the yellow blocked node col in 1st 2d array above, will e inserted into new table because it has 3 occurences in 2nd 2d array,
the number 3 came from user input
but since i'm using database object anyway, it cost me an expensive performance and time, too, i'm using vb.net 2005
i believe that there are alternative method for this problem.. could you all please tell me how the method? using mysql query or other method that could perform faster than one that i've tried?
best regards from me, thanks..
use linq its does all the mysql quires. You can find great documentation on it on msdn. Just build the db with mysql sever and use linq or entity they will both do all the commands for you. That way you can do data binding and save that info and pull it or whatever if you have more quesiton I have a copy of code in c# that uses tables for contact info I can see to you
This is a link to GitHub that contains the C# version using Linq
https://github.com/psychotiic/WebContactAppUsingLinq.cs
you will be able to use linq with that code that I just provided even though its C# its will be easy to figure out and if not you can find plenty of C# - VB code changers on the web for free.