Finding rank in hive - hadoop

I have a set of data
alex, 50
anu, 85
limi, 41
sam, 56
I need to find the rank of the students and store it in another column with the rank
eg:-
alex 50 3
anu 85 1
limi 41 4
sam 56 2
I tried with the rank function.
SELECT
a.name, a.mark,
rank() over (ORDER BY a.mark DESC) as rank
FROM
list a;
please help me.
thanks in advance!!

this is not working
First thing you need to do when you ask for help is to learn how to ask for help. "It does not work", "it errors" are not proper ways of asking. You need to specify always what error you get or how exactly it does not work. Does it crash? Does it print 'Hello, World!'? Does it make the speakers beep? We're not clairvoyant.
Now, about Window and Analytic functions in HIVE. They were introduced in HIVE 0.11, see HIVE-896. You can read the specification in the Hive Language Manual, including examples.
Make sure you run on Hive 0.11 to start with.

Related

In Dax, how can I get value from multiple columns with multiple criteria?

I am just a beginner in Dax language.
I googled it a lot to find solution, but failed.
Please help me to solve this problem.
Here are the two tables examples and there is no relation between them. ( I am using power query and power pivot)
I need to get sales location visitor from another table.
enter image description here
enter image description here
Branch
Date
Item
QTY
Sales Location
Visitor
USA.
2021.01.01
A.
23
1st floor
????
Canada
2021.01.02
B.
44
2nd floor
????
Date
USA's 1st floor visitor
USA's 2nd floor visitor
Canada's 1st floor visitor
Canada's 2nd floor visitor
2021.01.01
5435
664
2342
4532
2021.01.02
5345
345
2234
342
I tried to use IF and Lookupvalue, but it shows errors.
Could you please help me?
Thank you in advance.
You'll need to use Power Query to do some transformations to the second table so that it looks like this:
To do this, you'll have to transpose all columns, fill down the country column, and unpivot all other columns (highlight all other columns > unpivot columns). I'd then recommend adding a column to both tables that unites the country and sales location (USA-1st floor, USA-2nd floor, etc.) to both tables and use that as your connection in the model. You'll then be able to do a VLOOKUP using this united column between the tables.
Someone else may have a quicker answer but this should get you there!

Creating advanced SUMIF() calculations in Quicksight

I have a couple of joined Athena tables in Quicksight. The data looks something like this:
Ans_Count | ID | Alias
10 | 1 | A
10 | 1 | B
10 | 1 | C
20 | 2 | D
20 | 2 | E
20 | 2 | F
I want to create a calculated field such that it sums the Ans_Count column based on distinct IDs only. i.e., in the example above the result should be 30.
How do I do that?? Thanks!
Are you looking for the sum before or after applying a filter?
Sumif(Ans_Count,ID) may be what your looking for.
If you need to always return the result of the sum, regardless of the filter on the visual, look at the sumOver() function.
You can use distinctCountOver at PRE_AGG level to count unique number of values for a given partition. You could use that count to drive the sumIf condition as well.
Example : distinctCountOver(operand, [partition fields], PRE_AGG)
More details about what will be visual's group by specification and an example where there duplicate IDs will help give a specific solution.
It might even be as simple as minOver(Ans_Count, [ID], PRE_AGG) and using SUM aggregation on top of it in the visual.
If you want another column with the values repeated, use sumOver(Ans_Count, [ID], PRE_AGG). Or, if you want to aggregate via QuickSight, you would use sumOver(sum(Ans_Count), [ID]).
I agree with the above suggestions to use sumOver(sum(Ans_Count), [ID]).
I have yet to understand the use cases for pre_agg, so if anyone has concrete examples please share them!
Another suggestion would be to do a sumover + partition by in your table (if possible) before uploading the dataset, then checking if the results matche with Quicksight's aggregations. I find Quicksight can be tricky with calculated fields, aggregations, and nested ifs so I've been doing calculations in SQL where possible before bringing it in to quicksight to have a better grasp of what the outputs should look like. This obviously is an extra step, but can help in understanding how quicksight pulls off calcs and brings up figures (as the documentation doesn't always give much), and spotting things that don't look right (I've had a few) before you share your analysis with a wider group.

groupBy in laravel function similarly to distinct?

My records in 'answers table':
**id question_id answer**
20 12 app/Http/routes.ph
21 13 uri
22 13 closure
23 14 controller
24 15 class name
25 15 App\Http\Controllers
26 16 for displayh
My code to retrieve data:
$qas= DB::table('answers')
->groupBy('question_id')
->get();
dump($qas);
}
I get only 5 records instead of 7; where the other 2 records?
It works similarly to distinct function which is not my intention.
How to write code to get all 7 record which are grouped by 'question_id'?
Understand the concept of GroupBy, its mean that, it will consider same items as one, eg 14, 14-> 14 | 13,13-> 13 if you want to get all answer, then you have to write this
DB::table('answers')->get();
Edited
distinct and group by will do same action in your case.
If You can explain your problem in more details, then may be there is possible solution are.
You're talking about result with 7 rows, but that's not grouping. Maybe you're talking about ordering instead of grouping? If so, you'd want to use ->orderBy('question_id', 'asc'), that will give you 7 rows, sorted by question_id.
In SQL, GROUP BY clause is useful when you need to aggregate the result in a sort of way for example for SUM or AVERAGE of data.
Your case is different, you don't need to aggregate data using some function, you simply need a different data structure other than a simply and flat result list.
For your need, you should avoid GROUP BY, and reorder data in your code in a programmatic way.

Pulling data from Crystal Reports

My data is stored in Oracle and the only way I can run a report with it is using Crystal Reports. I have a set of data that looks like this ,,,,,,,,,,1, or ,1,,,,,,, or ,1,,,,,1,,,,1,. There are more variations.
Each one means a value is true for a record. There are about 54 'ticks/commas' What I want is all records with the one at the X spot. So for one report I may want all records in the 10th spot that have a 1. There may be other times where I want the records where the 1 is after spot 36. I agree it will pull other records but the main once I want is the X spot.
How do I get this? I tried a Like command but that does not narrow the data down far enough. I am familiar with SQL but not Crystal.
Any help would be great. TIA
In Crystal, you might try setting up a Parameter Field to hold a numeric value (1 to 54) then use that in a formula as the Record Selection. You'll be prompted to enter the parameter when you run the report.
In record selection i was initially going suggest the following which would bring back all records with 1 in the 12 spot. But this makes it hard to bring back a range.
split({yourfield},",")[12] = 1
This will bring back the same
instr({#test},"1") = 12
Then for your suggestion above you could use the following to bring back any record if it has a one in any spot after 36
instr({#test},"1") >= 37
As long as there is only one 1 in the field you can use this for other ranges as well.
Actually I don't want to disturb both answerts by Clayton Morris and CoSpringsGuy hence posting my answer.
You need to combine both the solutions to get the desired result.
Create a number parameter and provide either 1 to 57 numbers or keep just a filed to enter desired number.
Now in record selection use the formula given by CoSpringsGuy
if instr({databasefield.column},"1") = {?Inputnumber} --parameter field
then {databasefield.column}

SSRS Sorting values alphabetically within multiple columns

this is my first ever post so please be gentle with me..
I'm a novice SSRS report builder who is trying to achieve something I beleive is so simple, but I can't seem to fathom it. Any assistance or general points in any direction would be appreciated.
My data looks like this:
ID Measure 1 Barrier 1 Measure 2 Barrier 2 Measure 3 Barrier 3
01 Replace Lights Finance Review Contract Time Solar Panels Finance
02 Review Contract Time Solar Panels Time Replace Boiler Finance
03 Replace Boiler Disruption Replace lights Disruption Solar Panels Disruption
I need to be able to count how many times Finance is a barrier to each measure and how many times Disruption is a barrier to each measure and so on...
I think I should group or sort the data in order to apply a count expression but I am not sure of the best way to group or sort the data effectively to be able to render the results in a report.
Thanks in advance
Frustrated novice (aka JMS)
You should give a lot more information, I dont know what version of SQL you are using nor do I know where you get your data (if it is from sql it would be possible to get this data directly in the table from sql.)
In your dataset, add a expression column like this :
=SUM(IIF(Fields!Barrier1.Value = "Finance",1, 0))
and name it "Barrier1count"
in your table, right click on the last row, select insert row, outside group, bellow.
under any measure column, do a right click select expression, and paste this
=SUM(Fields!Barrier!Value)

Resources