Sorting and showing specific colums - sorting

I have data that I want to sort in my google sheets; but I want to show only specific columns and not others.
Here's an example :
Name
Type
HP
ATK
Hero1
type1
10
5
Hero2
type1
9
8
Hero3
type2
[null]
7
Hero4
type2
11
6
After a =SORT() in an other sheet; I'd like to have something like this :
Name
HP
Hero4
11
Hero1
10
Hero2
9
And with an other =SORT() have this :
Name
ATK
Hero2
8
Hero3
7
Hero4
6
Hero1
5
I tried with FILTER() But I can't manage to get rid of the Type column
Of course I don't want to modify the first table
But I could use sorted tables containing only the name and not wathever value was used to sort them
EDIT :

You can create a virtual array {A2:A,D2:D} and use
=SORT({A2:A,D2:D},2,0)
or even
=SORT({A2:A,C2:C},2,0)
(Do adjust the formula according to your ranges and locale)
In your case it would be:
=SORT({A2:A\D2:D};2;0)

One
=QUERY({A:D};"Select Col1,Col4 where Col1 <> '' Order by Col4 desc";1)
Two
=QUERY({A:D};"Select Col1,Col3 where Col1 <> '' Order by Col3 desc";1)
QUERY

use:
=SORT(FILTER({A2:A\C2:C}; C2:C<>""); 2; )
and:
=SORT(FILTER({A2:A\D2:D}; D2:D<>""); 2; )
pros: SORT with FILTER is faster and more reliable than QUERY that can eat your data
also, see how to convert commas to semicolons: https://stackoverflow.com/a/73767720/5632629

Related

how to sort 2 different columns in google sheet individually?

I have a Google Sheet that has 2 columns with integer rows in it. Both these columns have no relation to each other. But when I apply a A->Z sort on the 1st column the 2nd column values also change and vice versa. My task is to SORT these 2 columns individually in ascending order and create a 3rd column which checks if the values of this 1st 2 column are equal or not.
Example:
Col1 Col2
4 5
1 8
2 9
5 1
Expected Output after sorting them individually:
col1 col2
1 1
2 5
4 8
5 9
Solution 1:
You can filter and sort each column separately:
Solution 2:
Another solution would be to create the desired output by sorting each column separately and concatenating the results:
={{"Col1";sort(A2:A)},{"Col2";sort(B2:B)}}

Allow multiple values from SSRS in oracle

I have a query that gets contract_types 1 to 10. This query is being used in an SSRS report to filter out a larger dataset. I am using -1 for nulls and -2 for all.
I would like to know how we would allow multiple values - does oracle concatenate the inputs together so '1,2,3' would be passed in? Say we get select -1,0,1 in SSRS, how could we alter the bottom query to return values?
My query to get ContractTypes:
SELECT
ContractType,
CASE WHEN ContractType = -2 THEN 'All'
WHEN ContractType = -1 THEN'Null'
ELSE to_Char(ContractType)
END AS DisplayFigure
FROM ContractTypes
which returns
ContractType DisplayFig
-1 Null
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
This currently is only returning single values or all, not muliple values:
SELECT *
FROM Employee
WHERE NVL(CONTRACT_TYPE, -1) = :contract_type or :contract_type = -2
I'm assuming we want to do something like:
WHERE NVL(CONTRACT_TYPE, -1) IN (:contract_type)
But this doesn't seem to work.
Data in Employee
Name ContractType
Bob 1
Sue 0
Bill Null
Joe 2
In my report, I want to be able to select contract_type as -1(null),0,1 using the 'allow muliple values' checkbox. At the moment, I can only select either 'all' using my -2 value, or single contract types.
My input would be: contract type = -1,1,2
My output would be Bill, Bob, Joe.
This is how I'm executing my code
I use SSRS with Oracle a lot so I see where you're coming from. Thankfully, they work pretty well together.
First make sure the parameter is set to allow multiple values. This adds a Select All option to your dropdown so you don't have to worry about adding a special case for "All". You'll want to make sure the dataset for the parameter has a row with -1 as the Value and a friendly description for the Label.
Next, the WHERE clause would be just as you mentioned:
WHERE NVL(CONTRACT_TYPE, -1) IN (:contract_type)
SSRS automatically populates the values. There is no XML or string manipulation needed. Keep in mind that this will not work with single-value parameters.
If for some reason this still doesn't work as expected in your environment, there is another workaround you can use which is more universal and works even with ODBC connections.
In the dataset parameter properties, use an expression like this to concatenate the values into a single, comma-separated string:
="," + Join(Parameters!Parameter.Value, ",") + ","
Then use an expression like this in your WHERE clause:
where :parameter like '%,' + Column + ',%'
Obviously, this is less efficient because it most likely won't be using an index, but it works.
I don't know SSRS, but - if I understood you correctly, you'll have to split that comma-separated values list into rows. Something like in this example:
SQL> select *
2 from dept
3 where deptno in (select regexp_substr('&&contract_type', '[^,]+', 1, level)
4 from dual
5 connect by level <= regexp_count('&&contract_type', ',') + 1
6 );
Enter value for contract_type: 10,20,40
DEPTNO DNAME LOC
---------- -------------------- --------------------
20 RESEARCH DALLAS
10 ACCOUNTING NEW YORK
40 OPERATIONS BOSTON
SQL>
Applied to your code:
select *
from employee
where nvl(contract_type, -1) in (select regexp_substr(:contract_type, '[^,]+', 1, level)
from dual
connect by level <= regexp_substr(:contract_type, ',') + 1
)
If you have the comma separated list of numbers and then if you like to split it then, the below seems simple and easy to maintain.
select to_number(column_value) from xmltable(:val);
Inputs: 1,2,3,4
Output:
I guess I understood your problem. If I am correct the below should solve your problem:
with inputs(Name, ContractType) as
(
select 'Bob', 1 from dual union all
select 'Sue', 0 from dual union all
select 'Bill', Null from dual union all
select 'Joe', 2 from dual
)
select *
from inputs
where decode(:ContractType,'-2',-2,nvl(ContractType,-1)) in (select to_number(column_value) from xmltable(:ContractType))
Inputs: -1,1,2
Output:
Inputs: -2
Output:

Is it possible to disaggregate in hive sql? [duplicate]

I'm trying to find a way to split a row in Hive into multiple rows based on a delimited column. For instance taking a result set:
ID1 Subs
1 1, 2
2 2, 3
And returning:
ID1 Subs
1 1
1 2
2 2
2 3
I've found some road signs at http://osdir.com/ml/hive-user-hadoop-apache/2009-09/msg00092.html, however I wasn't able enough detail to point me in the direction of a solution, and I don't know how I would set up the transform function to return an object that would split the rows.
Try this wording
SELECT ID1, Sub
FROM tableName lateral view explode(split(Subs,',')) Subs AS Sub
SELECT ID1, new_Subs_clmn
FROM tableName lateral view explode(split(Subs,',')) Subs AS new_Sub_clmn;
I was initially confused with the names used, sharing the above query thinking it would be of help.

SSRS Switch Case - how to sort by 2 field values

=Switch(Fields!RptSeq.Value="1",Fields!PatientId.Value,
Fields!RptSeq.Value="2",Fields!RxNumber.Value,Fields!PatientId.Value
Fields!RptSeq.Value="5",Fields!DoctorName.Value,Fields!PatientId.Value,
1=1,Fields!PatientId.Value)
I need to sort my report thrugh expression like this, if the sort seq is 1 then by patient ID, if 2 then the report should be first sorted by RxNumber then by PatientID. I don't know how to sort for 2 field values.
if I do Fields!RxNumber.Value,Fields!PatientId.Value the sort does not work, if I do Fields!RxNumber.Value+Fields!PatientId.Value I'm getting error wrong sort expression.
appreciate your help
Thanks in advance.
you can add two lines in the sorting tab of the tablix; one for the first sort priority with this expression:
=Switch(Fields!RptSeq.Value="1",Fields!PatientId.Value,
Fields!RptSeq.Value="2",Fields!RxNumber.Value,
Fields!RptSeq.Value="5",Fields!DoctorName.Value,
1=1,Fields!PatientId.Value)
and the other for the second sort priority set the field to :
Fields!PatientId.Value
You can handle it by passing the parameter to the Dataset query also.
Sample:
declare #RptSeq int = 1
select * from Table
order by
(case #RptSeq when 1 then PatientId
when 2 then RxNumber
when 5 then DoctorName
else PatientId
end),
(case #RptSeq when 2 then PatientId
when 5 then PatientId
end)

How can I get values from one table to another via similar values?

I have a table called excel that has 3 columns, name, id, and full_name. The name part is the only one I have and I need to fill id and full_name. The other table that contains the data is called tim_pismena and has 2 columns that I need, id and pismeno_name (the actual names are not important, but i'm writing them just for clarity). In pseudooracle code :) the select that gets me the values from the second table would be done something like this:
SELECT tp.id, tp.pismeno_name
FROM tim_pismena tp
WHERE upper(tp.pismeno_name) LIKE IN upper('%(SELECT name FROM excel)%')
and when used with an insert, the end result should be something like
name id full_name
Happy Joe 55 Very fun place Happy Joe, isn't it?
Use merge statement
1 MERGE
2 INTO excel tgt
3 USING tim_pismenae src
4 ON ( upper(src.naziv_pismena) LIKE '%'||upper(tgt.ime)||'%')
5 WHEN MATCHED
6 THEN
7 UPDATE
8 SET tgt.id = src.id
9 , tgt.full_name = src.naziv_pismena
10 WHEN NOT MATCHED
11 THEN
12 INSERT ( tgt.name
13 , tgt.id
14 , tgt.full_name )
15 VALUES ( src.naziv_pismena
16 , src.id
17 , src.naziv_pismena )
18 WHERE (1 <> 1);

Resources