How to display a 1 to many query result in a single row?
Hi,
I want to display a 1 to many relationship in a query in just one row. The current result is that I get more than 1 rows. How can I display it in one column with the additional attribute in a column, without repeating? Thank you.
Select s.student, t.teacher from student_table s, teacher_table t where s.id = t.student_id
Result
Student Teacher
John Doe Larry Woe
John Doe Mary Moe
I would rather get a result like this:
Result
Student Teacher 1 Teacher 2
John Doe Larry Woe Mary Woe
Edited by: Samantha on May 18, 2011 2:48 PM
Hi,
Will all Students have exactly two Teachers?
If not picture your sample with two more Students.
One having 1 Teacher
One having N Teachers
Think about N, what will it be? - How would you create a table with N columns?
If you can't easily answer above, re-consider what you are trying.
That said, it could still be done - even if all Students do not have exactly two Teachers - and is called Pivot a dynamic number of columns.
Examples are in FAQ
SQL and PL/SQL FAQ
Still a bad idea, with or without known number of teachers
Regards
Peter
Similar Messages
-
I need to print one query result as a single row
Hi,
I need to print one query result as a single row ,which gives more than one value (of subinventories)and also i would like to print the quantity of that particular subinventory at particular place.Please suggest how can i do this in the report builder?Actually I need to print inventory report with subinventory break up.For that all subinventories of category code AB are taken as single row.Based on that subinventory value Quantity must be printed at that particular place.
For ex
Quantity
Item no Description Subinventory Code AB_Abc AB_Def AB_ghi
1 ***** 12 9
2 ****** 8 5
like that.I am waiting for the reply.Plz its some how urgent.
Thank you, -
How to display all the characteristics in a MultiProvider in a single Row?
Hi
I have a requirement as follows :
The MP has data from 2 cubes C1 and C2 as follows:
Char1 Char2 Char3 Char4 KYF1 KYF2 KYF3
C1 1 2 3 # 10 20 #
C2 1 2 # 4 # 50 60
means blank ie. the char is not present in a constituent Cube.
My Report rquirement is :
Char1 Char2 Char3 Char4 KYF1 KYF2 KYF3
1 2 3 4 10 70 60
Kindly suggest how to achieve this in Query Designer7.0?
Thanks,
Aparna.Hi,
Multicube is based on Join and therefore all the charateristics which are part of the report like rows of the report or in the drill down of the report..... should be part of the both the cubes.
Either you can have same char and key figures from both the cubes in the report or char from both the cube and key from any cubes.Then only the values will come in single records.
Its not possible to combine the char from one cube and key figure from others in case of multicube and will give you result in two different rows.
You should go for infoset for those cases.
Thanks
Ajeet -
Function to concatenate all query results in a single row comma separeted
Hi All,
my version is Oracle 10.2.0.4.0
this is my query:
select distinct
table1.id
from table1,
table2,
table3
where table1.id = table2.id
and table2.id = table3.id
and table3.id = '761'
and result is:
61
18
68B
S05
S18
68
could someone provide me a function (or something else) in order to have a result like this:
61,18,68B,S05,S18,68
and call it from another query?
I appreciate your help.
Many thanks.
Alessandrouser12889282 wrote:
could someone provide me a function (or something else) in order to have a result like this:
61,18,68B,S05,S18,68
and call it from another query?But this is the wrong way to do it. Better use the original query as a subquery for your second query.
let me demonstrate it
select *
from someotherTable x
where x.FK_ID IN (select t1.id
from table1 t1
table2 t2,
table3 t3
where t1.id = t2.id
and t2.id = t3.id
and t3.id = 761 /* use numbers not strings for IDs! */
;Edited by: Sven W. on Jul 30, 2010 10:17 AM -
How to view complete date stamp in query result view in sql developer?
Hi,
In the query result, the date present in db is shown as DD-MM-YYYY format but I want to view the complete date stamp. When I view the same data in aqua data studio, I see the complete time stamp. Please let me know if I need to do some settings in Oracle SQL Developer so that complete date is shown?
How to view complete date stamp in query result view in sql developer?
Thanks in advance,
Vineet864793 wrote:
Hi,
In the query result, the date present in db is shown as DD-MM-YYYY format but I want to view the complete date stamp. When I view the same data in aqua data studio, I see the complete time stamp. Please let me know if I need to do some settings in Oracle SQL Developer so that complete date is shown?
How to view complete date stamp in query result view in sql developer?
Thanks in advance,
VineetAlternatively you can execute below
set nls_date_format='DD-MM-YYYY HH24:MI:SS';Regards,
Achyut K -
How to display an image in an alv grid in each corresponding row?
Hi,
please tell me how to display an image in an alv grid in each corresponding row, like;;
tony 23 newyork <image>
Mkitharyan 63 washington <image>
NOT BY HOTSPOTS/URL.you can put image in each cell you want:
data lo_cmp_usage type ref to if_wd_component_usage.
lo_cmp_usage = wd_this->wd_cpuse_alv( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).
DATA lo_value TYPE ref to cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model( ).
data col type ref to CL_SALV_WD_COLUMN.
col = lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'IMAGE' ).
data image type ref to cl_salv_wd_uie_image.
CREATE OBJECT image.
image->SET_SOURCE_FIELDNAME( 'IMAGE' ).
COL->SET_CELL_EDITOR( image ). -
Query results:every other record/row grey and white
Hello guys,
query results:every other record/row grey and white
how would you make every other record/rows a different color
just like the forums color. Lightest grey and white?
<cfquery name="Myqueryname"
datasource="#Request.MainDSN#">
SELECT
CompanyID,
CompanyName,
Address,
City,
State,
ZipCode,
Comments
FROM
Company
ORDER BY
CompanyName ASC
</cfquery>
<html>
<head>
<title>CF TUTORIALS</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>All CO Listings</h1>
<table>
<tr>
<td><b>ID</b></td>
<td><b>Name</b></td>
<td><b>Address</b></td>
<td><b>City</b></td>
<td><b>State</b></td>
<td><b>ZIP Code</b></td>
<td> </td>
</tr>
<cfoutput query="Myqueryname">
<tr>
<td>#CompanyID#</td>
<td>#CompanyName#</td>
<td>#Address#</td>
<td>#City#</td>
<td>#State#</td>
<td>#ZipCode#</td>
<td>
<a href=" ALL Emps.cfm?CompanyID=#CompanyID#">ALL
Emps</a>
<a href=" AddCO Form.cfm">AddCO</a>
<a href="
Editco.cfm?CompanyID=#CompanyID#">Editco</a>
<a
href="CoDeleteForm.cfm?CompanyID=#CompanyID#">Delete</a>
</td>
</tr>
</cfoutput>
</table>
</body>
</html>There is a cool tool in Coldfusion called MOD
This basically calculates the remainder of the row number
when divided.
I interpreted its use to something like this, which has
worked for me.
<cfoutput query="qry_requestedlist" maxrows="30"
startrow="1">
<cfset EvenRow=#CurrentRow# +1>
<cfif CurrentRow Mod 2 IS 1>
<tr>
<th class="grey" CurrentRow#</th>
<cfelse>
<th class="white">#CurrentRow#</th>
<tr>
</cfif>
</cfoutput>
I doubt this is precisely what you want but this is the sort
of thing. -
Is there a way to combine their query results into a single function
say I have a bunch of functions that return a query:
<cffunction name="getDeals" access="remote"
returntype="query">
<cffunction name="getDeals2" access="remote"
returntype="query">
is there a way to combine their query results into a single
function that returns a struct of the various results?Umm, it's probably more suited to an array - effectively
making it into a list of queries. You'd then loop the array and
output each.
I use a similar approach when creating system messages to the
user. Most of my functions that are called do their bit, then at
the end call another function I call "messages". This function
grabs whatever my function sends and appends it to a messages
array.
This way enables me to output a long list of messages -
because I could be calling several functions at the same time. If I
just output a message from each function, each one would overwrite
the other. So I'd get one message at a time.
Immediately after it's output, I then destroy the message
array so that old messages aren't kept inside of it.
Mikey. -
How to display output of from clause query?
Hi. I am using Forms Developer 10g. I have a datablock which uses a from_clause_query. In my from_clause_query, i used a WITH AS SELECT.
I am trying to display the output of this query in my forms but the first column, V_CUTOFF_TO is not displayed, probably because it is not a database item. It was a result of my initial WITH AS SELECT query months. How can i display this along with the output of my from_clause_query. Thanks in advance for the help. By the way, i am trying to post the contents of my from_clause_query here but it says Sorry, this content is not allowed. I dont know why?Here is how you should most your code for it to be legible.
WITH months AS
(SELECT ADD_MONTHS(:V_DATE_FROM,LEVEL-1) m_first ,
(ADD_MONTHS(:V_DATE_FROM, LEVEL -0 )-1) m_last
FROM dual
CONNECT BY LEVEL < MONTHS_BETWEEN(:V_DATE_TO,:V_DATE_FROM) + 1
EQUIP_per_month AS
(SELECT COUNT(TRANS_CODE) V_COUNT,
m_last V_CUTOFF_TO,
trans_code,
transformer,
DATE_COMMISSION,
DATE_DECOMMISSION,
CLASSIFICATION,
SUBSTATION_CODE
FROM
(SELECT C.TRANS_CODE,
C.TRANSFORMER,
C.SUBSTATION_CODE,
C.DATE_COMMISSION,
C.DATE_DECOMMISSION,
C.CLASSIFICATION,
m_last
FROM SPM_TRANS C
CROSS JOIN months
WHERE CLASSIFICATION IS NOT NULL
AND SUBSTR(C.SUBSTATION_CODE,6,4) <>'M001'
AND C.DATE_COMMISSION IS NOT NULL
AND (C.DATE_PRIVATELY_OWNED IS NULL
OR C.DATE_PRIVATELY_OWNED > m_first)
AND (SUBSTR(C.TRANS_CODE,5,1) '5'
AND SUBSTR(C.TRANS_CODE,5,1) '9')
AND (:P_GRID = SUBSTR(C.SUBSTATION_CODE, 1,1)
OR :P_GRID IS NULL)
AND (:P_REGION = SUBSTR(C.SUBSTATION_CODE, 2,4)
OR :P_REGION IS NULL)
AND (C.DATE_DECOMMISSION > m_first
OR C.DATE_DECOMMISSION IS NULL)
AND C.DATE_COMMISSION <= m_last
AND (:P_BRANCH =
(SELECT DISTINCT BRANCH_CODE
FROM SPM_SUBSTATIONS
WHERE C.SUBSTATION_CODE = SUBSTATION_CODE
OR :P_BRANCH IS NULL)
AND (:P_ACC =
(SELECT DISTINCT ACC_CODE
FROM SPM_SUBSTATIONS
WHERE C.SUBSTATION_CODE = SUBSTATION_CODE
OR :P_ACC IS NULL)
AND (:P_DISTRICT = SUBSTR(C.SUBSTATION_CODE, 6,4)
OR :P_DISTRICT IS NULL)
AND (RTRIM(:P_CLASSIFICATION) = RTRIM(CLASSIFICATION)
OR :P_CLASSIFICATION IS NULL)
AND (:P_VOLTLEVEL = SUBSTR(C.TRANS_CODE, 1,1)
OR :P_VOLTLEVEL IS NULL)
GROUP BY m_lAst,
trans_code,
transformer,
DATE_COMMISSION,
DATE_DECOMMISSION,
CLASSIFICATION,
SUBSTATION_CODE
SELECT V_CUTOFF_TO,
A.trans_code,
S.SUBSTATION_CODE,
A.transformer,
A.DATE_COMMISSION,
A.DATE_DECOMMISSION,
A.CLASSIFICATION
FROM
(SELECT *
FROM
(SELECT trans_code,
transformer,
DATE_COMMISSION,
DATE_DECOMMISSION,
CLASSIFICATION,
SUBSTATION_CODE,
V_CUTOFF_TO
FROM EQUIP_per_month
GROUP BY trans_code,
transformer,
DATE_COMMISSION,
DATE_DECOMMISSION,
CLASSIFICATION,
SUBSTATION_CODE,
V_CUTOFF_TO
) A,
SPM_SUBSTATIONS S
WHERE A.SUBSTATION_CODE = S.SUBSTATION_CODE
ORDER BY V_CUTOFF_TO,
S.SUBSTATION_CODE,
TRANS_CODE);The V_CUTOFF_TO , your first column, may not to be getting a (not null ) value.
Regards,
Edited by: Prabodh on Jun 21, 2012 2:41 PM -
How to put variable selection and the query result the same screen
Dear all,
how can I put the variable selection and the query result in the same screen? Please advise. Thanks.
Jin MingNot sure if you are saying you want the prompts on the same page as the results... however in 7.0 with BEx Analyzer, you can insert a text object from the design toolbar and assign it to the variable.... this way, lets say you run query for period 6, then the text object will display "6" on the same area where the query results are.
-
How to display a empty (non-existing) column and info in LAST row
Hello!
I´m trying to create the code that diplays all authors (author.name), empty COLUMN, NR_OF_BOOK_PER_AUTHOR.
I want the LAST ROW to display: (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all books
Headache: How do I display the EMPTY column and how do I get the LAST ROW to display column1) 'Sum:', (column2) nr of authors, (column3) total sum of all books
It should look like this:
AUTHOR EMPTY NR_OF_BOOKS_PER_AUTHOR
I can list all authors and NR_OF_BOOKS_PER_AUTHOR using this code:
SELECT A.NAME, COUNT(B.ROWID)
FROM AUTHOR A, BOOK B
WHERE B.AUTHOR_ID = A.ID
GROUP BY A.NAME
ORDER BY COUNT(B.ROWID)
I can count the numbers of authors (should be displayed in last row column2) using:
SELECT COUNT(name)
FROM author
and I can list the total amount of books (should be displayed in last row column3) using:
SELECT COUNT(title)
FROM book
But I come up short with how to display the EMPTY column and the last row containing (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all books
Any suggestions?
Best regards,
DanielI want the LAST ROW to display: (column1) the word 'Sum:', (column2) nr of authors, (column3) total sum of all booksHave a look at GROUP BY with CUBE or ROLLUP.
Cheers, APC -
How to set query result to a single window
I am using SQL Developer 2.1063, and not happy with the default setting of result window. Everytimes when I run a query, the result appear in a new result window. Over a couple of hour I have tense or hundreds of result tabs in the low window. It is not quite fun to remove them one by one.
I am sure it can be set so that all result appear in one result window, as I am used to in the old SQ Developer version. But I failed to find it in Prefernces and in Help.-K- wrote:
This is fixed in the available 2.1.1.
Have fun,
K. K
I've just tested on 2.1.1 and i came to the same conclusion as user10369687
- if you check the box for "Preferences - Database - Worksheet - Automatically Freeze Result Tabs" or click the pin button or run as script (F5) or highlight the sql and run as script (F5) you always get new query result tab.
The option name suggest that if you check the box the same result tab will be used for different queries which is not true, is the oposite way.
If the option name is changed than the confusion will be cleared.
Dani -
Query - Purchasing information in single row
Hi Experts,
I have a requirement to create a report which shows products with all POs in a single row. In many cases we will have several open PO at one time for the same product. For example - item SUFF2231-M will have:
PO
Qty
Due Date
42771
200
10/05/2014
42883
250
20/05/2014
43321
150
30/05/2014
43375
100
10/06/2014
43401
100
20/06/2014
We only need to see up to 5 PO for each product. Ideally I need to be read them on a single line like so:
ItemCode
PO1
Qty1
DueDate1
PO2
Qty2
DueDate2
PO3
Qty3
DueDate3
PO4
Qty4
DueDate4
PO5
Qty5
DueDate5
SUFF2231-M
42771
200
10/05/2014
42883
250
20/05/2014
43321
150
30/05/2014
43375
100
10/06/2014
43401
100
20/06/2014
Is this possibe using only SQL query?
Regards
GeoffHi Geoff,
You can use the ROW_NUMBER and CASE Functions to acheive this. Here with , i have give u a small idea with an ex:
Qry :
B.ItemCode,SUM(B.PO1)[PO1],SUM(B.POQty1)[POQty1],SUM(B.PO2)[PO2],SUM(B.POQty2)[POQty2] From
select Itemcode
CASE when Sno=1 Then DocNum End [PO1]
CASE When Sno=1 Then Qty End [POQty1]
CASE when Sno=2 Then DocNum End [PO2]
CASE When Sno=2 Then Qty End [POQty2]
From(
Row_Number() Over (Order By Opor.Docnum) [Sno], Opor.DocNum,POr1.ItemCode,sum(POr1.Quantity)[Qty] from OPOR join Por1 on Opor.DocEntry=por1.DocEntry
ItemCode='20002' group by oPor.DocNum,por1.ItemCode
A where A.Sno<=2)B Group By B.ItemCode
Result :-
ItemCode PO1 POQty1 PO2 POQty2
20002 18 1.000000 19 10.000000
Thanks,
Karthikeyan.P -
How to add an Attachments Table on the Page of a Single Row Region
Dear All,
Please help me with a tutorial or anything that help me adding a an Attachments Table on the Page of a Single Row Region.
I took a look at the attachment in ch4 in the developer guide but it is not explained clearly how to implement it.
Thanks,
Mahmoud Assem
Message was edited by:
Mahmoud AssemIf you follow the dev guide properly, there shouldn't be any issue. Let us know where exactly you are facing the issue.
--Shiv -
Query results more than 200 rows.
Hi all:
I have a problem with a query that results more than 200 rows.
Only show in a table 201 rows and warning about this message: "Query has exceeded 200 rows. Potentially more rows exist, please restrict your query."
Is possible that the query show all results ???
thanks!Its still a warning. You can continue with work but definitely you can increase the value through the profile value. Anything within 500 wouldn't cause much performance issue.
--Shiv
Maybe you are looking for
-
I bought a used PowerMacPC G5. I can burn and read DVDs, but I can't read or burn CDs. The CDs are not even recognized. After the drive searches for a while, the CD is ejected without any error messages. The CDs work okay on my iMac. I am running Mac
-
Preview in browser not showing changes in muse
I am trying to preview my changes in Muse but it's not showing any updates. I've doubled checked updates and shut down my laptop to reboot but still not working.
-
More trouble with exporting for web
Alright, Sorry to say but I am still having trouble converting/exporting my film trailer to the website for PC users to be able to access it. I converted it to a quicktime movie film from FCP, which plays beautifully but apparently PC users can't see
-
Table control with wizard in module pool
Hi Gurus!! First I have an ztable for header and ztable for item of the purchase order. We have the requirement of first uploading the data into ztable and then perform bapi or bdc on it. So, before the data goes into the ztable we have to create scr
-
Function 0012 does not exist when saving contact???
Has anyone seen these before?? I also get Function 0022 does not exist errors also? Thanks