Displaying SQL Query results in rows instead of Columns
Hi,
I'm fairly new to Oracle so forgive me if this is a really stupid question.
I used Mysql for a while and if I wanted to display query results in rows instead of columns I could end the SQL command with '\G' instead of a semicolon.
This would give me output like...
Column_1: AAAA
Column_2: BBBB
Column_3: CCCC
Instead of the normal
Column_1 Column_2 Column_3
AAAAAA BBBBBBB CCCCCCC
Is there an equivalent in SQLPlus to the MySQL \G termination?
Thanks.
John
> so forgive me if this is a really stupid question.
It is certainly not a stupid question, but pivoting is a very frequently asked and answered question:
[url http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15]http://forums.oracle.com/forums/search.jspa?threadID=&q=pivot&objID=f75&dateRange=all&userID=&numResults=15
In 11g you have special PIVOT and UNPIVOT functions.
Regards,
Rob.
Similar Messages
-
i have a c++ form that accepts data and saves it on a table in a database via a button click, this is the code for the eventprivate: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDatabase=gcnew MySqlCommand("insert into test.Data(Full_Name,Matric_No) values('"+this->textBox1->Text+"','"+this->textBox10->Text+"') ;" ,conDatabase);
MySqlDataReader^ myReader;
try{
conDatabase->Open();
myReader=cmdDatabase->ExecuteReader();
MessageBox::Show("Saved");
while(myReader->Read()){
}catch(Exception^ex){
MessageBox::Show(ex->Message);
NOW i want to send a query to give out this information in a new form or in a form exactly like the one used to enter the data, this is how far i have come
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
MyForm ^ Form = gcnew MyForm(this);
Form->ShowDialog();
String^ constring=L"datasource=localhost;port=3306;username=root;password=lampard";
MySqlConnection^ conDatabase=gcnew MySqlConnection(constring);
MySqlCommand^ cmdDatabase=gcnew MySqlCommand("Select * from test.Data where Matric_No='"+textBox1->Text +"';",conDatabase);
MySqlDataReader^ myReader;
try{
conDatabase->Open();
myReader=cmdDatabase->ExecuteReader();
while(myReader->Read()){
textBox1->Text ;
}catch(Exception^ex){
MessageBox::Show(ex->Message);
NOte: MyForm is the title of the form used to enter in the data sent to the database please how do i get the program to display the data meeting the query criteria into a form?i made textBox1 a public memeber of MyForm class and i changed
Form->ShowDialog(); to Form->Show() and i entered the code you advised me to and it displayed the result.i am very grateful, thank you -
Displaying SQL query results in tabular fashion
Hi,
I've a table having following three fields."Market segment","Status","No of Cust".
This table contains the name of market segment, name of user status(4 in no) and number of customers belonging to that status.
I need to create a query that will show the result in a tabular manner.like the following
Market segment.....status1.....status2........status3.......Total
MS1...................... 5..............6............... 7................18
ms2........................1..............6................8...............15
Total.......................x..............y.................z................T
(Ignore the dots(.))
Can some one help me with the query?
Thanks,
jajatiSee this link:
http://tonyandrews.blogspot.com/2004/10/pivot-queries.html -
SQL Query results to CSV as two worksheets
I'm trying to take two SQL queries and get the results sent to a CSV file on two worksheets. Looking online I have not found a solid example of using the Excel ComObject to create a CSV then add a new worksheet to the CSV file. An added bonus
would be using AutoFit on the columns so everything is easily visible.
Code found online got me the following script which does work, however it takes 12 minutes to pipe the SQL queries to Excel. Switching to a CSV and the script executes in 5 seconds.
This is another nice to have, I was also looking the best way to look at the results (only 1 column) and depending on the length of the data, insert what Excel would call a Cell thereby shifting cells RIGHT but so far have found no clear examples of how
to accomplish that. My guess would be modifying my SQL queries but I've posted a question on StackOverFlow and someone suggested modifying the PowerShell Table created from the SQL dataset.Tables
Code:
$docs = "C:\Scripts\Output.xlsx"
If (Test-Path $docs){Remove-Item $docs}
Function Run-Query {
param([string[]]$queries,[string[]]$sheetnames)
## - Create an Excel Application instance:
$xlsObj = New-Object -ComObject Excel.Application
$xlsObj.DisplayAlerts = $false
$xlsWb = $xlsobj.Workbooks.Add(1)
## - Create new Workbook and Sheet (Visible = 1 / 0 not visible)
$xlsObj.Visible = 0
$time = 2
for ($i = 0; $i -lt $queries.Count; $i++){
$percentage = $i / $time
$remaining = New-TimeSpan -Seconds ($time - $i)
$message = "{0:p0} complete" -f $percentage, $remaining
Write-Progress -Activity "Creating Daily Reboot Spreadsheet" -status $message -PercentComplete ($percentage * 100)
$query = $queries[$i]
$sheetname = $sheetnames[$i]
$xlsSh = $xlsWb.Worksheets.Add([System.Reflection.Missing]::Value, $xlsWb.Worksheets.Item($xlsWb.Worksheets.Count))
$xlsSh.Name = $sheetname
### SQL query results sent to Excel
$SQLServer = 'ServerName'
$Database = 'DataBase'
## - Connect to SQL Server using non-SMO class 'System.Data':
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $query
$SqlCmd.Connection = $SqlConnection
## - Extract and build the SQL data object '$Table2':
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$Table1 = $DataSet.Tables["Table"]
## - Build the Excel column heading:
[Array] $getColumnNames = $Table1.Columns | SELECT ColumnName
## - Build column header:
[Int] $RowHeader = 1
foreach ($ColH in $getColumnNames)
$xlsSh.Cells.item(1, $RowHeader).font.bold = $true
$xlsSh.Cells.item(1, $RowHeader) = $ColH.ColumnName
$RowHeader++
## - Adding the data start in row 2 column 1:
[Int] $rowData = 2
[Int] $colData = 1
foreach ($rec in $Table1.Rows)
foreach ($Coln in $getColumnNames)
## - Next line convert cell to be text only:
$xlsSh.Cells.NumberFormat = "@"
## - Populating columns:
$xlsSh.Cells.Item($rowData, $colData) = $rec.$($Coln.ColumnName).ToString()
$ColData++
$rowData++; $ColData = 1
## - Adjusting columns in the Excel sheet:
$xlsRng = $xlsSH.usedRange
[void] $xlsRng.EntireColumn.AutoFit()
}#End For loop.
#Delete unwanted Sheet1.
$xlsWb.Sheets.Item('Sheet1').Delete()
#Set Monday to Active Sheet upon opening Workbook.
$xlsWb.Sheets.Item('Cert').Activate()
## ---------- Saving file and Terminating Excel Application ---------- ##
$xlsFile = "C:\Scripts\Output.xlsx"
[void] $xlsObj.ActiveWorkbook.SaveAs($xlsFile)
$xlsObj.Quit()
## - End of Script - ##
start-sleep 2
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsSh)) {'cleanup xlsSh'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsWb)) {'cleanup xlsWb'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsObj)) {'cleanup xlsObj'}
[gc]::collect() | Out-Null
[gc]::WaitForPendingFinalizers() | Out-Null
}#End Function
$queries = @()
$queries += "Query1"
$queries += "Query2"
$sheetnames = @('Cert','Prod')
Run-Query -queries $queries -sheetnames $sheetnamesHere's what I ended up with that accomplishes my goal. I learned it's not possible to create a CSV with two worksheets since Excel will allow this but the CSV cannot be saved with the second worksheet. Instead, I create two CSV files then merge
them into one Excel workbook, one CSV per worksheet. In my case, this happens in 5 seconds. There is one thing which must be mentioned, I've seen this script fail the first time it is run but will successfully run the second time.
Also note, after much trial and error, this code correctly cleans up the Excel ComObject!! -Thanks go to JRV.
$docs = "D:\Scripts\MonthlyReboots.xlsx"
IF (Test-Path $docs){Remove-Item $docs}
$csv1 = "D:\Scripts\Cert.csv"
IF (Test-Path $csv1){Remove-Item $csv1}
$csv2 = "D:\Scripts\Prod.csv"
IF (Test-Path $csv2){Remove-Item $csv2}
Function Run-Query {
param([string[]]$queries,[string[]]$sheetnames,[string[]]$filenames)
Begin{
$SQLServer = 'ServerName'
$Database = 'DataBase'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $Database; Integrated Security = True"
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = 0
$dest = $Excel.Workbooks.Add(1)
}#End Begin
Process{
For($i = 0; $i -lt $queries.Count; $i++){
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $queries[$i]
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0] | Export-Csv -NoTypeInformation -Path "D:\Scripts\$($sheetnames[$i]).csv" -Force
}#end for loop.
}#End Process
End{
$SqlConnection.Close()
#Excel magic test!
For($i = 0; $i -lt $queries.Count; $i++){
$loopy = (Resolve-Path -Path $filenames[$i]).ProviderPath
$Book = $Excel.Workbooks.Open($loopy)
$next = $Excel.workbooks.Open($loopy)
$next.ActiveSheet.Move($dest.ActiveSheet)
$xlsRng = $dest.ActiveSheet.UsedRange
$xlsRng.EntireColumn.AutoFit() | Out-Null
$dest.sheets.item('Sheet1').Delete()
$xlsFile = "D:\Scripts\MonthlyReboots.xlsx"
[void] $Excel.ActiveWorkbook.SaveAs($xlsFile)
$Excel.Quit()
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlsRng)) {'cleanup xlsRng'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($next)) {'cleanup xlsSh'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Book)) {'cleanup xlsWb'}
While ([System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)) {'cleanup xlsObj'}
[gc]::collect() | Out-Null
[gc]::WaitForPendingFinalizers() | Out-Null
}#End end block.
}#End function run-query.
$queries = @()
$queries += @'
Select * from table1
$queries += @'
Select * from table2
$sheetnames = @("Cert","Prod")
$filenames = @("D:\Scripts\Prod.csv","D:\Scripts\Cert.csv")
Run-Query -queries $queries -sheetnames $sheetnames -filenames $filenames
Start-Sleep -Milliseconds 50
Invoke-Item D:\Scripts\MonthlyReboots.xlsx -
Set Text Item To SQL Query Result
I am trying to set a text item to a SQL query result. Something like the following:
(I am trying to accomplish this in the SOURCE portion, set to 'SQL Query' source type, of the text item properties)
SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
This only displays as the literal text when the application renders and not the value from the SQL query.
I apologize if this has already been posted but I could not find what I am looking for. I have seen posts that reference a pre-region computation but do not know the exact steps to accomplish the results I want.
Thanks in advance for anyone's time to help me with my issue.
KyleScott,
The literal that displayed (I have fixed it) was the actual SQL statement: SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
I have resolved the issue, using SQL Query as the "Source Type" and Always, replacing any existing value in session state as the "Source Used" for the properties of the item.
What I was trying to accomplish is a search text item that would return the data for that record in a table into other text items, for each column in that record, for update; based on the search text item as a unique SQL query search for that record.
Thank you for your quick reply!
Kyle -
How to display the query results in several pages?.
Hi,
i want to display the query results in several pages. for example my query result found 50 matches, now i want to print 20 per pages next 20 will be in next pages. iam using only jsp & mysql.
Regards
ChinnaHi, what you are trying accomplish is known as pagination.
You could use JSTL tags with Custom Tags to perform pagination in your JSP pages.
evnafets showed me DisplayTags , you could use those as well http://displaytag.sourceforge.net/11/tut_externalSortAndPage.html
Here is one article on paging:
http://www.javaworld.com/javaworld/jw-07-2004/jw-0726-pagination.html -
Display the query result in an Excel file??
hi there..
am writing one script file that queries my DB and display the query result in an Excel file??
i.e: if my query is :
select col1, col2
from table;
and i want the results to dispalys in 2 col. in an Excel spreadsheet..
Appreaciating ur cooperation..
Mouradset colsep to a delimiter that is not normally part of your data like |
also setup the environment with these other setup commands
Set Echo Off;
Set Concat Off;
Set Pagesize 9999;
Set Feedback Off;
Set Verify Off;
Set Term Off;
Set Space 0;
Set Colsep '|'
Set Underline Off;
If you wanted to use a comma delimiter the setup would be same but the set colsep='","'
with the addition of concatenating a " on the first col and last col of the query
eg.
-- if first col and last_col are character types then
SELECT '"'||col1,....,last_col||'"'
FROM table;
Otherwise if either is a number they would have to be converted with a TO_CHAR -
Displaying jtable as rows instead of columns
This may be really simple, but I can't figure it out. I want to display information in a JTable as rows instead of columns. Can anyone help me with this?
Thanks in advance,
mCheck here:
http://www2.gol.com/users/tame/swing/examples/SwingExam
les.html
They may well have what you want, if not they will
probably have some ideas you can use.There's always the swing tutorial, also. I learned JTables from the tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html and it gave me a lot of good ideas and points to start from.
You could probably create your own cell renderer (or use the header renderer) and set the first column to use that to display their text. -
Query result Alternate row with different color
hello
can anyone help me on a query result.
i wish to have a :
query result Alternate row with different color .
ex.
first row light grey
second row darker grey.
and repeats itself up to the last record/row.
thanks<tr> <!------------------------------I replaced with
<tr bgcolor="<cfif currentrow mod
2>##D3D3D3<cfelse>##F5F5F5</cfif>">
<td>
#MYARRAY[x][2].CNO#
</td>
<td align="center">
#MYARRAY[x][2].CDCDTt#
</td>
<td>
#MYARRAY[x][2].PADESC#
</td>
<td align="center">
#MYARRAY[x][2].INc#
</td>
<td align="center">
#MYARRAY[x][2].Exp#
</td>
<cfset thirdArray = MYARRAY[x][3]>
<cfif NOT arraylen(thirdArray)>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<cfelse>
<cfloop index="z" from="1" to="3">
<cfif z GT arraylen(thirdArray)>
<td> </td>
<td> </td>
<cfelse>
<td>
#thirdArray[z][2]#
</td>
<td>
#thirdArray[z][3]#
</td>
</cfif>
</cfloop>
<cfif arrayLen(thirdArray) gt 3>
<td nowrap="nowrap">
<cfloop index="z" from="4" to="#arraylen(thirdArray)#">
#thirdArray[z][2]# - #thirdArray[z][3]#<BR />
</cfloop>
</td>
</cfif>
</cfif>
</tr>
I got this error.
Variable CURRENTROW is undefined -
[Excel] Running a SQL Query to delete rows
Hello Experts,
Background: I am attempting to use a dba of my companies time keeping system and implement it with Power BI tools. Given the file size restrictions within Power Bi itself I need to lower my file size by removing all time logs from
inactive employees.
I have a question regarding whether or not you can use a sql query to delete rows in excel. I have roughly 200,000+ rows in my excel spreadsheet. I am attempting to delete all rows where an employee equals inactive. I have attempted to
delete these rows by sorting them and doing a bulk delete and clear contents, but it seems to crash my excel every time. My thought process is that using a query that does a timed delete might put less of a burden on deleting the massive amount of data.
I would like to use this: DELETE * FROM [Table_(...)_Actual$] WHERE [Current] = "Inactive" (Will add more once I know it is possible to use sql queries in Excel.
Any information on whether or not this is possible would be appreciated.
Regards,
LinkRunning SQL Query in Excel is possible, however, the delete query is not supported in Excel.
You are more restricted in deleting Excel data than data from a relational data source. In a relational database, "row" has no meaning or existence apart from "record"; in an Excel worksheet, this is not true. You can delete values
in fields (cells). Please see:http://support.microsoft.com/kb/257819/en-us
One workaround : Use update query to set the rows as null, then use select query.
e.g.
SQL = "update [sheet2$A1:B5] set name=null,age=null where name='andy'"
cnn.Execute SQL
SQL = "select name,age from [sheet2$A1:B5] where name is not null"
Wind Zhang
TechNet Community Support -
QA: Designer's operation to Add one more Field to display in Query Result Web Part
QUESTION ABOUT Query Result Web Part presentation +1 Field
I'd be looking at a property of Web Part to look up Discussion Board through Query Result Web Part. Currently it displays 'Title' column of Discussion Board, and my caring requirement is presentation customization to hold double
columns of 'Title'+'Updated Date'. How could I add one more field 'Updated Date' to display in addition to that preexisting 'Title' field?
Any procedural steps to realize how to add Filed to display in Query Result Web Part?Hi Yoshihiro,
As I understand, you want to add the field to display in Query Result Web Part in SharePoint 2013.
Which web part does you use? Content query web part or search results web part?
If you use search results web part, you could edit the discussion board result template and add the updated field in the template.
You could go to Design Manager: Edit Display Templates (site setting-> look and feel->design manager->edit display template), download the Discussion Item.htm file, and edit the file.
After editing, upload the file.
The articles below are about how to modify an existing Display Template in SharePoint 2013.
http://www.learningsharepoint.com/2012/09/17/sharepoint-2013-the-new-display-templates-for-styling-your-content/
http://blogs.technet.com/b/sharepoint_quick_reads/archive/2013/08/01/sharepoint-2013-customize-display-template-for-content-by-search-web-part-cswp-part-1.aspx
If you use content query web part, you could edit the content query web part, in the Property Mappings section select the “Change the mapping of managed”, and add the “modifiedOWSDATE” (it means the last modified date) in the line, after
that you could see the update date under the title.
Best regards,
Sara Fan
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Data Display -- SQL Query?
Hi
This might be simple but, I have no idea.. how to achieve this via a simple SQL Query..
Data in a column :
1
5
6
15
25
30
35
Should do a SELECT showing like this..
1 5
6 15
25 30
35 NULL
Thanks!create table t1
(numcol number);
insert into t1 values(1);
insert into t1 values(5);
insert into t1 values(6);
insert into t1 values(15);
insert into t1 values(25);
insert into t1 values(30);
insert into t1 values(35);
commit;
select odds.numcol, evens.numcol
from
select numcol
,row_number() over (order by numcol) rn
from
select numcol
,row_number() over (order by numcol) rn
from t1
where mod(rn,2) <> 0
) odds
select numcol
,row_number() over (order by numcol) rn
from
select numcol
,row_number() over (order by numcol) rn
from t1
where mod(rn,2) = 0
) evens
where odds.rn = evens.rn (+);
NUMCOL NUMCOL
1 5
6 15
25 30
35 -
Sql query slowness due to rank and columns with null values:
Sql query slowness due to rank and columns with null values:
I have the following table in database with around 10 millions records:
Declaration:
create table PropertyOwners (
[Key] int not null primary key,
PropertyKey int not null,
BoughtDate DateTime,
OwnerKey int null,
GroupKey int null
go
[Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
With the following index:
CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]
[PropertyKey] ASC,
[BoughtDate] DESC,
[OwnerKey] DESC,
[GroupKey] DESC
go
Description of the case:
For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
declare @ownerKey int = 40000
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from (
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
) as result
where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
May be the slowness is due to as OwnerKey/GroupKey in the table can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
view.
Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
go
declare @ownerKey int = 1
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from #result as result
where result.[Rank]=1
and result.[OwnerKey]=@ownerKey
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
SQL query results. more than 10 rows
Home>SQL>SQL Commands
Results tab says
More than 10 rows available. Increase rows selector to view more rows.
How can I "Increase rows selector to view more rows."?Sim,
above the text area for the sql command you find a combobox with the label "Display". Initially only 10 records will be displayed.
~Dietmar. -
How to display ID and Type in a row instead of column
I have a table A with ID_NO, TYPE, PUBID(foreign key).
The type can be CAT, ISBN, ISSN. I also have another table B with PUB_ID (primary key) and a lot of other details.
The requirements are to display the results as rows like this:
PUB_NO | CAT | ISBN | ISSN
222 | abc | qwe | zxc
I know it would be easy to display like this:
ID_NO | TYPE | PUB_NO
abc | CAT | 222
qwe | ISBN | 222
zxc | ISSN | 222
But I need it in a row instead. I was thinking of getting all PUB_NOs and looping through each to get the rest in a PL/SQL procedure but is this the best approach?
I can't wrap my head around this. I'm not a DB expert and I haven't done any PL/SQL in a very long time.
Thanks for your help
MarcelJohn:
<quote>
I did point out the need for unique types in my original post with the MAX/DECODE solution.
</quote>
Indeed, you did. Sorry about that ... I looked closely only at your last post with the two SQLs and missed the caveat you had included in the first post.
:o) ... couldn't stop myself ... one last loose [but reasonable?!?!] thing [I can think of] to keep those 2 sql different:
insert into pubDetail values (333,'333');
â¦
flip@FLOP> select * from pubDetail;
Â
PUB_NO PUB_DATA
111 111
222 222
333 333
Â
flip@FLOP> select * from test_a;
Â
ID_NO TYPE PUB_NO
abc CAT 111
def CAT 222
qwe ISBN 111
xyz ISSN 222
Â
flip@FLOP> SELECT d.pub_no, a.cat, b.isbn, c.issn
2 FROM pubDetail d,
3 (SELECT pub_no, id_no cat
4 FROM test_a
5 WHERE type = 'CAT') a,
6 (SELECT pub_no, id_no isbn
7 FROM test_a
8 WHERE type = 'ISBN') b,
9 (SELECT pub_no, id_no issn
10 FROM test_a
11 WHERE type = 'ISSN') c
12 WHERE d.pub_no = a.pub_no(+) AND
13 d.pub_no = b.pub_no(+) AND
14 d.pub_no = c.pub_no(+)
15 ;
Â
PUB_NO CAT ISBN ISSN
111 abc qwe
222 def xyz
333
Â
flip@FLOP> SELECT d.pub_no
2 ,MAX(DECODE(a.type, 'CAT' , id_no)) cat
3 ,MAX(DECODE(a.type, 'ISBN', id_no)) isbn
4 ,MAX(DECODE(a.type, 'ISSN', id_no)) issn
5 FROM pubDetail d, test_a a
6 WHERE d.pub_no = a.pub_no
7 AND a.type IN ('CAT', 'ISBN', 'ISSN')
8 GROUP BY d.pub_no
9 ;
Â
PUB_NO CAT ISBN ISSN
111 abc qwe
222 def xyzHope you take this only as a bit of humor [about incomplete requirements] ⦠I like your stuff!
Maybe you are looking for
-
Changing base for calculation of Tax
Hi All, SAP standard delivers 0001 condition type in Tax calculation procedure as base for calculation of Tax. condition type 0001 picks up 0PR0 as base for calcualtion of tax. Can someone tell me how does system picks up 0PR0 as base for calculation
-
ACL won't work in 10.5.4 is it a bug??
Using a MacMini with System 10.5.4 as a simple file server for 6 persons doesn't work correctly: I made two groups: work and executive, 6 persons as sharing only (3 with access to work the others access to both groups. On the second partition I made
-
Hello, Can anyone tell me if there is a monopoly game for the Classic? The one in Itunes Store seems to be for the touch. Thanks. Keith
-
Report on No of Opportunities in sales Stage
Hi All, I have a requirement to display following report: Report should have 5 coloum 1) Current Sales Stage of Opportunity 2) No of opportunities which are in current stage from 3 months 3 ) No of opportunities which are in current stage from 6 mont
-
Many problems installing Quicktime+iTunes
(Keep in mind I have windows 7 64 bit) I need the firmware update for my iPhone 3g, which normally I avoid because I always seem to have a problem with quicktime installing properly. But since a couple up my apps needed to work, I gave in. When I tri