sql dev query moving multiple rows to many columns - oracle

I am very new to sql dev and have a query with results below...
TeacherID TFirstName TLastName StudentID SFirstName SLastName
11113 Doe John 12345 Jane1 Doe1
11113 Doe John 12346 Jane2 Doe2
11113 Doe John 12347 Jane3 Doe3
I get many rows of one teacher with all their students in rows.
I want one teacher with all the students in columns.
Teacherid tfirstname tlastname studentid sfirstname slastname studentid sfirstname slastname studentid sfirstname slastname
11113 Doe John 12345 Jane1 Doe1 12346 Jane2 Doe2 12347 Jane3 Doe3
and so on for the 20 students in this class.
Is this possible? Like I said I am new to sql dev.

Related

Neo4J : How to Order results by attributes value

How do I order my results using Node properties value using Cypher Queries?
For Example :
I have the below results :
Person
City
Kasper
London
Sean
Chicago
Tom
London
Kate
New York
John
London
Sarah
Chicago
I want to sort the above result on basis of "London" i.e people from London should be on top. The sorted results can look something like this :
Person
City
Kasper
London
John
London
Tom
London
Kate
New York
Sean
Chicago
Sarah
Chicago
I know Order By clause can be used to sort in ascending or descending order but can we use it to sort on the basis of Value? If not, please suggest some other way to do it. Thanks in advance.
you can sort by property value . imagine (p:Person) and (c:City) nodes
RETURN p.name AS Person, c.name AS City
ORDER BY City
another example
WITH p,c
ORDER BY p.birthdate
RETURN p.name AS Person, c.name AS City
in case you want to order by age.
if your cities have to be in an order based on a specific property, add e.g. index to the city node , and do something like:
WITH p,c
ORDER BY c.index
RETURN p.name AS Person, c.name AS City

How to categorize data in a ORACLE table based on a primary key?

I have a table TRAVEL with column TRIP_ID as primary key.
SOURCE DATA
TRIP_ID PERSON_NAME DESTINATION SOURCE TRANSACTION_ID TRIP_COUNT
100 Mike London Zurich 1000B112 1
101 Mike Paris Capetown 1000B112 1
102 Mike Moscow Madrid 1000B112 1
103 John Delhi Moscow 1100A110 1
104 John Toronto Zurich 1100A110 1
105 Mary Chennai Madrid 1100A111 1
106 Mary Berlin Zurich 1100A111 1
EXPECTED RESULTS:
when I do select * from TRAVEL where TRANSACTION_ID = 1100A111 it returns below two rows as below .
so I want my data to be categorized based on the transaction_ID on a run time.I dont want to hardcode the value for transaction-ID each time as above but i want to group it in such a way that it should fetch me the above expected results.I mean it should return all the data which are corresponding to the TransactionID in the table and it should not sum up the TRIP COUNT.It should return me the rows as below in my table.I am ok to create view .Please suggest
TRIP_ID PERSON_NAME DESTINATION SOURCE TRANSACTION_ID TRIP_COUNT
105 Mary Chennai Madrid 1100A111 1
106 Mary Berlin Zurich 1100A111 1
Can someone suggest a query in ORACLE to handle this ? I donot want to hardcode transaction ID
Regards
Sameer

Google sheets function : Filter records by multiple condition

I have 2 sheets : Sheet1 has large number of records with columns Firstname, Lastname and Company. Another Sheet2 has same columns but small set of records. I want only those records from sheet1 which have a matching firstname and lastname in sheet2 but company is different. How can I achieve this with help of a formula? (it has to be scale-able).
E.g.
Sheet1
Firstname Lastname Company
John Doe ABC
Jon Smith XXX
Dan S. XXX
John Davies XXX
Sheet2
Firstname Lastname Company
John Davies ABC
Jon Smith XXX
Expected output :
Firstname Lastname Company
John Davies XXX
Try below formula:
=SORT(IFERROR(ARRAYFORMULA(SPLIT(ARRAYFORMULA(VLOOKUP(ARRAYFORMULA(E2:E&" "&F2:F&" "&C2:C),ARRAYFORMULA(A2:A&" "&B2:B&" "&C2:C),1,0))," ")),""),1,false)

How can I do a UNION operation with DexieJS?

I have a indexedDB with firstName and lastName as columns.
Here is some sample data:
firstName lastName
__________________
John Doe
Mary Doe
Jacob Adams
Doe Mary
When I search for Doe, the query should return the first two entries and the last. If I search for Jacob, it should return the second last.
I followed examples from this Dexie sample, but I can't do a single search on two fields at the same time. If not, is there a way to run two questions and UNION the results to a single one?
Sounds like this:
table.where('firstName').equals('Doe').or('lastName').equals('Doe')

Perl JOIN-like behavior in Oracle?

I have two tables, let's call them PERSON and NAME.
PERSON
person_id
dob
NAME
name_id
person_id
name
And let's say that the NAME table has data like:
name_id person_id name
1 1 Joe
2 1 Fred
3 1 Sam
4 2 Jane
5 2 Kim
I need a query (Oracle 10g) that will return
name_id names
1 Joe, Fred, Sam
2 Jane, Kim
Is there a simple way to do this?
Update:
According to the article that figs was kind enough to provide, starting in 9i you can do:
SELECT wmsys.wm_concat(dname) departments FROM dept;
For this example, the answer becomes:
SELECT name_id, wmsys.wm_concat(name) from names group by name_id
The short answer is to use a PL/SQL function. For more details, have a look in this post.

Resources