Query to align data together
Hello All
I have 3 tables say A, B, C
Each contain a column called ID
The number of rows in each table can vary.
I want the output to be like this, so that it aligns the same ids from the 3 tables
in the same row.
Wherever the Id is not present in the table it should be replaced by X
A.ID B.ID C.ID
1 1 X
2 X 2
3 3 X
4 4 X
5 X 5
6 6 6
X 7 X
X 8 X
X X 9
Thanks
Acchu
Solution 1
Outer joining combined with union
select nvl(to_char(a_id), 'X') aId
, nvl(to_char(b_id), 'X') bId
, nvl(to_char(c_id), 'X') cId
from (select a.id a_id
, b.id b_id
, c.id c_id
from table_a a
, table_b b
, table_c c
where b.id = a.id(+)
and b.id = c.id(+)
union
select a.id
, b.id
, c.id
from table_a a
, table_b b
, table_c c
where a.id = b.id(+)
and a.id = c.id(+)
union
select a.id
, b.id
, c.id
from table_a a
, table_b b
, table_c c
where c.id = b.id(+)
and c.id = a.id(+))
order by nvl(b_id, nvl(a_id, c_id))Solution 2
A quick and dirty solution which will work as long as
1) the id's of table_a, table_b and table_c are integers
2) the highest id is lower than the number of rows in the user_objects table
select nvl(to_char(a.id), 'X') a_id
, nvl(to_char(b.id), 'X') b_id
, nvl(to_char(c.id), 'X') c_id
from table_a a
, table_b b
, table_c c
, (select rownum fake_id
from user_objects) obj
where obj.fake_id = a.id(+)
and obj.fake_id = b.id(+)
and obj.fake_id = c.id(+)
and (a.id is not null
or
b.id is not null
or
c.id is not null)
Similar Messages
-
Need help in query to display dates as start, end dates
Hi,
I am trying the following output from the below table structure, data
StartDAte Endate Reason duration
12-02-09 12:00:00 12-02-09 13:10:20 planned activity 1:10:20
01-04-09 08:30:34 01-04-09 15:00:20 planned activity 6:30:34
12-04-09 17:10:45 12-04-09 17:11:04 unplanned activity 0.10
23-05-09 22:00:11 23:05-09 22:15:09 planned activity 0.15
Mdate Reason omode host
12-02-09 12:00:00 planned activity st 366
12-02-09 13:10:20 planned activity ed 366
01-04-09 08:30:34 planned activity st 366
01-04-09 15:00:20 planned activity ed 366
12-04-09 17:10:45 unplanned activity st 366
12-04-09 17:11:04 unplanned activity ed 366
23-05-09 22:00:11 planned activity st 366
23:05-09 22:15:09 planned activity ed 366
i tried with individual query but not able to get the output in combined way of start, end dates together with calculation of time difference, i tried using case options but not successful in resolve it.
select to_char(mdate,'dd-mm-yyyyy hh24:mi:ss')startdate, reason
from date_md where omode like 'st'
order by o_char(mdate,'dd-mm-yyyyy hh24:mi:ss')startdate;
select to_char(mdate,'dd-mm-yyyyy hh24:mi:ss')enddate, reason
from date_md where omode like 'ed'
order by o_char(mdate,'dd-mm-yyyyy hh24:mi:ss')enddate;
any suggestions on type of query should be used is welcomed.Or maybe
SQL> WITH t AS (SELECT TO_DATE ('12-02-09 12:00:00',
'DD-MM-YY HH24:MI:SS')
event_date,
'planned activity' activity,
'st' start_end,
366 HOST
FROM DUAL
UNION ALL
SELECT TO_DATE ('12-02-09 13:10:20',
'DD-MM-YY HH24:MI:SS'),
'planned activity',
'ed',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('01-04-09 08:30:34',
'DD-MM-YY HH24:MI:SS'),
'planned activity',
'st',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('01-04-09 15:00:20',
'DD-MM-YY HH24:MI:SS'),
'planned activity',
'ed',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('12-04-09 17:10:45',
'DD-MM-YY HH24:MI:SS'),
'unplanned activity',
'st',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('12-04-09 17:11:04',
'DD-MM-YY HH24:MI:SS'),
'unplanned activity',
'ed',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('23-05-09 22:00:11',
'DD-MM-YY HH24:MI:SS'),
'planned activity',
'st',
366
FROM DUAL
UNION ALL
SELECT TO_DATE ('23-05-09 22:15:09',
'DD-MM-YY HH24:MI:SS'),
'planned activity',
'ed',
366
FROM DUAL)
SELECT MIN (event_date) startdate,
MAX (event_date) enddate,
MAX (activity) reason,
NUMTODSINTERVAL (MAX (event_date) - MIN (event_date),
'day')
duration
FROM t
GROUP BY TRUNC (event_date)
STARTDATE ENDDATE REASON DURATION
23.05.2009 22:00:11 23.05.2009 22:15:09 planned activity +00 00:14:57.999999
12.02.2009 12:00:00 12.02.2009 13:10:20 planned activity +00 01:10:19.999999
01.04.2009 08:30:34 01.04.2009 15:00:20 planned activity +00 06:29:45.999999
12.04.2009 17:10:45 12.04.2009 17:11:04 unplanned activity +00 00:00:18.999999
4 rows selected. -
Getting data in a query on last date of all previous months
Dear Experts,
I need your help with a query.
I am trying to create a query which when run should pick the number of Open Sales Order on the last date of all the previous months from the start of company.
I could create the query for fetching the required data on last day of the previous month, say today is 25th June 2014, so my query only fetches data for May 31st 2014 but I need data for all previous month, May 31st 2014, April 30th 2014, March 31st 2014 & so on.
Please advise how to achieve this is SQL query.
Thanks & regards,
NitinHi,
Try this:
Select *
from(
SELECT T0.[DocNum] as #,t0.cardcode as C, t0.docdate
FROM ORDR T0
WHERE T0.[DocStatus] = 'o' and T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-1,0)),10) OR T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-2,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-3,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-4,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-5,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-6,0)),10) or T0.[DocDate] = CONVERT(VARCHAR(10), DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())-7,0)),10)
group by t0.cardcode,docdate,T0.[DocNum]) S
pivot
(count(#) for c in([cvt01],[cvt02],[cvt03],[cvt04],[cvt05],[cvt06],[cvt07],[cvt08],[cvt12])) P
Note: Replace Cvt01,02...with your customer code.
Thanks & Regards,
Nagarajan -
POWER QUERY Get External Data From File From Folder (Excel 2013)
Hi,
Beginner's question :
What could be the use of the query on a folder : we just get a list of files with their path. What can we do with that?
ThanksHi,
Do you want to combine data from multiple Excel Files in the same folder path into one table? If I understand correct, we can add a custom column to import the data.
After we getting a list of files with their path, the Query Editor window will activate to show you a table containing a record for each file in the chosen directory. These will provide our function with the needed FilePath and FileName parameters.
Function sample: File name([Folder path],[Field name]
For more detailed steps, please see the article:
http://datapigtechnologies.com/blog/index.php/using-power-query-to-combine-data-from-multiple-excel-files-into-one-table/
Please Note: Since the web site is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
how can i open a PDF bank statement in "numbers" so that the rows and columns contain properly aligned data from statement?
Numbers can store pdfs pages or clippings but does not directly open pdf files. To get the bank statement into Numbers as a table I would open the bank statment in Preview (or Skim) or some pdf viewer.
Then hold the option key while selecting a column of data.
Then copy
Then switch to numbers and paste the column into a table
Then repeat for the other columns in the pdf document
It would be easier (in my opinion) to download the QFX or CSV version from your bank -
Data driven subscription query returns no data
We have a data driven subscription on SSRS 2008 R2. The columns in the query are tied to one or more parameters of the report. When we run the subscription and if the query does not return any rows, I was hoping that the subscription will not start; however,
instead, to my surprise, I got error stating..."Parameter XYZ value can't be null". How to avoid this error and keep subscription from running in this situation?
Example: I have a report that required employeeID as a parameter. I have a query (step 3: data driven subscription) that fetches employee ID based on some criteria. If there is no row returned by the query; It throws error on report stating "Parameter
EmployeeID can't be null."
Nehal JainHello Nehal -
Try adding a UNION ALL to your parameter dataset query like
UNION ALL SELECT NULL AS EmployeeID , ..
Just check accordingly. I ll revert again based on this , got a priority now.
Happy to help! Thanks. Regards and good Wishes, Deepak. http://deepaksqlmsbusinessintelligence.blogspot.com/ -
Web Analysis Error -- Error while executing query and retrieving data
Regarding Web Analysis:
We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error.
The error is:
Error while executing query and retrieving data.; nested exception is:
com.hyperion.ap.APException: [1033] Native:
1013033[Thu Oct 22 09:08:17
2009]server name/application name/database name/user name/Error91013033)
ReportWriter exit abnormally
Does anyone have any insight into what is going on?
My version information is:
Hyperion System 9 BI+ Analytic Administration Services 9.3.0.1.1 Build 2
Web Analysis 9.3.0.0.0.286
Thanks in advance for your help.
DaveWHi,
And also click on check option by opening the query in Query designer,as Mr . Arun suggested.
And if you get any error in checking, see the long message(detail).
With rgds,
Anil Kumar Sharma .P -
Select query to read data from a view
Hi friends,
We have been using a query to read data from a custom view which used to work perfectly. Now the program sits at that select query forever. We are able to extract same data from se16. Not sure what could be the problem.
Thanks in advance.Dev
Have a look at the Table Index for the tables involved in the View... I think there is some change in the Indexes.. (Add / Remove / Change)
Thanks
Amol Lohade -
Error when executing a query on master data
Hi Friends,
When I execute a query fon Master Data Characteristic infoObject ( 0BPARTNER ) from BEx Analyzer I got the below error. 0BPARTNER contains 15 attributes. I am getting the below error only for this query. Rest all other queries are working good with the same BEx Analyzer.
<b>An error occured in the communication with the BW Server.
Due to this connection has to be closed.</b>
<b>Detailed Description:
The system is configured incorrectly.</b>
Please tell me what could be the problem? How to overcome this?
Thanks,
SasiHi Arun,
Before the execution of query I did that. And it was ' Query is Correct'.
Any more ideas?
Thanks,
Sasi. -
How to use a query in matrix data retrive
hai everybody
how to use a query in matrix data retrive...
pls ..If u have created a UDT to store the data then U can retrive the data through recordset.
oRecordset.doquery("SQL Statement")
If u have taken the DB Data source to Manipulate then
then type
oMatrix.flushtoDataSource
then
U can retrive the data through DB Data source.
-Manmath -
Query regarding the data type for fetcing records from multiple ODS tables
hey guys;
i have a query regarding the data type for fetcing records from multiple ODS tables.
if i have 2 table with a same column name then in the datatype under parent row node i cant add 2 nodes with the same name.
can any one help with some suggestion.Hi Mudit,
One option would be to go as mentioned by Padamja , prefxing the table name to the column name or another would be to use the AS keyoword in your SQL statement.
AS is used to rename the column name when data is being selected from your DB.
So, the query Select ename as empname from emptable will return the data with column name as empname.
Regards,
Bhavesh -
How do I align data within a column?
In the newly updated Numbers (Mac), I cannot find how to align data within a column.
The justify data select the column by clicking the column header (the letter at the top of the column) then open the formatter (top right):
then select the "Text" formatter and select the type of aligment you want: -
Query from the data abse and pass values to a pdf form
query from the data abse and pass values to a pdf form
Hello
Hello i have this html report that i have written to output a
report.
now, i am assigned to pass the same fields to a pdf form so
the fields in the adaobe form can be populated or the term
Pre-populate the form.
can anyone help me get started.
first i would like to know if it can be done.
second, what do i need to get started (tools )
third how do i do this.
i am really lost at this point.
can anyone give me tips in how to approach this
subject??It can be one using Adobe Acrobat Designer which is packaged
with Acrobat
Professional Pro 7. It uses all XML to create and populate
forms.
If you had the time, you can also create <cfdocument
type="pdf"> to have
them ready and just pass the info to it so it autogenerates
the PDF on the
fly. -
Hi,
I am trying to output only a successful job during the past 24 hrs of each day. If there is job that has an outcome of a success and a failure within the last
24 hrs for each day, I want to only output the successful one. If there are no success for the same job, I will output the last attempted failed job.
Here are my columns:
current output:
JOB_ID JOBDATE GROUP PATH OUTCOME FAILED LEVEL ASSET
3400908 7/27/2012 10:01:18 AM polA target1 Success 0 incr clone1
3400907 7/27/2012 10:01:09 AM polA target1 Failed 0 incr clone1
3389180 7/23/2012 10:01:14 AM polA target1 Failed 1 incr clone1
3374713 7/23/2012 10:01:03 AM polA target1 Success 0 incr clone1
3374712 7/22/2012 11:24:32 AM polA target1 Success 0 Full clone1
3367074 7/22/2012 11:24:00 AM polA target1 Failed 1 Full clone1
3167074 7/21/2012 10:01:13 AM polA target1 Success 0 incr clone1
336074 7/21/2012 10:01:08 AM polA target1 Success 0 incr clone1
desired output:
JOB_ID JOBDATE GROUP PATH OUTCOME FAILED LEVEL ASSET
3400908 7/27/2012 10:01:18 AM polA target1 Success 0 incr clone1
3374713 7/23/2012 10:01:03 AM polA target1 Success 0 incr clone1
3374712 7/22/2012 11:24:32 AM polA target1 Success 0 Full clone1
3167074 7/21/2012 10:01:13 AM polA target1 Success 0 incr clone1
Here is a code I am trying to use without success:
select *
from
(selectjob_id, jobdate, group, path, outcome, Failed, level, asset,
ROW_NUMBER() OVER(PARTITION BY group, path, asset ORDER BY jobdate desc) as rn
from job_table where jobdate between trunc(jobdate) and trunc(jobdate) -1 )
where rn = 1
order by jobdate desc;Thanks,
-AbeHi, Abe,
You're on the right track, using ROW_NUMBER to assign numbers, and picking only #1 in the main query. The main thing you're missing is the PARTITION BY clause.
You want to assign a #1 for each distinct combination of group_id, path, asset and calendar day , right?
Then you need to PARTITION BY group_id, path, asset and calendar day . I think you realized that when you named this thread "Query Based *on date partition* ".
The next thing is the analytic ORDER BY clause. To see which row in each partition gets assigned #1, you need to order the rows by outcome ('Success' first, then 'Failed'), and after that, by jobdate (latest jobdate first, which is DESCending order).
If so, this is what you want:
WITH got_r_num AS
SELECT j.* -- or list columns wanted
, ROW_NUMBER () OVER ( PARTITION BY group_id -- GROUP is not a good column name
, path
, asset
, TRUNC (jobdate)
ORDER BY CASE outcome
WHEN 'Succcess'
THEN 1
ELSE 2
END
, jobdate DESC
) AS r_num
FROM job_table j
WHERE outcome IN ('Success', 'Failed')
-- AND ... -- Any other filtering, if needed
SELECT * -- or list all columns except r_num
FROM got_r_num
WHERE r_num = 1
;If you'd care to post CREATE TABLE and INSERT statements for the sample data, then I could test it.
It looks like you posted multiple copies of this thread. I'll bet that's not your fault; this site can cause that. Even though it's not your fault, please mark all the duplicate versions of this thread as "Answered" right away, and continue in this thread if necessary.
Edited by: Frank Kulash on Jul 28, 2012 11:47 PM
This site is flakier than I thought! I did see at least 3 copies of this same thread earlier, but I don't see them now. -
Select Query Based on date condition
Hi ,
Is it Possible.
i want to run select query based on date condition.
Eg...
if the date between 01-jan-01 and 01-jan-05 then
select * from table1;
if the date between 02-jan-05 and 01-jan-08 then
select * from table2;
Becaz i have data in 2 diffrent tables , based on the date condition i wnt to run the select statement to diffrent tables.
i dont want plsql here Just SQL needed.
thanks,
-R
Edited by: infant_raj on May 5, 2009 11:48 PMHelo Kanish,
this is not the one i was asking..
wht i mean was .
i use bind variable to get date while running the select statement , once i get the date then i want to choose any one of the table to run select query.
EG..
select col1,col2 from table1 where date between only if 01-jan-01 and 01-jan-05;
select col1,col2 from table2 where date between only if 02-jan-05 and 01-jan-08;
Run any one of the two . not all
thanks,
_raj
Maybe you are looking for
-
Hi, i thought it would be easy ti find how to do it nut from searching this site and with google i couldn;t find the answer for that. i have blobs in a table (jpg,doc,pdf ...) . how can i display those blobs (jpg,doc,pdf ...) in forms6i ? can you giv
-
Need help in drawing inside the Oval and outside it
I need help in something I have an array and I want the numbers to be around the oval and I have part of the array and I want to fill part of the oval and when I want to put a number I would like a line from the center to point at the number I know i
-
How to activate the business function HCM and HCM_LSO_CI_2
Hi! To use the role of course administrator 1.4, we have to activate the business function HCM, Learning Solution 02 (HCM_LSO_CI_2). On IMG, I do not see about HCM_LSO_CI_2. Could you tell me the right way to do that? Please help. Thanks!
-
I'm new to java so please forgive any confusion with terminology etc, I'm currently sourcing a good reference text to use. Basically I've got an AbstractTableModel class (MyTableModel) that creates a table model. To create the table model its constru
-
Empty record in (detail record)
Hello all of you, i have detail block,, and in that block, it is not necessary to write in all field . i want that when the user fetch the record, the empty field fill with red color,, is it possible example item # | Name | Detail | Qty | Issu_date|