Changing Order Of Results (Union)
Hi All,
This simple query;
SELECT DISTINCT client_id FROM order_header
UNION
SELECT '1Forza WIP' FROM dual
UNION
SELECT 'Total' FROM dualReturns this data;
CLIENT ID
1Forza WIP
DAIRNUNEAT
FORZCLECKH
GBI-FELIXS
GU-LONDON
NOM-TELFOR
PLUMALRESF
PURECORBY
RIVELONDON
TRADNORFOL
TSC-SCUNTH
Total
YOPLPARISIs there anything I can do with order by (or another function) to change the results to look like this;
CLIENT ID
1Forza WIP
DAIRNUNEAT
FORZCLECKH
GBI-FELIXS
GU-LONDON
NOM-TELFOR
PLUMALRESF
PURECORBY
RIVELONDON
TRADNORFOL
TSC-SCUNTH
YOPLPARIS
TotalNotice 'Total' is now displayed last.
Thanks in advance.
SM.
Hi,
Given that you know the value that has to be last:
ORDER BY NULLIF (client_id, 'Total') NULLS LASTA more general solution is to add a column to be used for sorting:
SELECT DISTINCT client_id
, 0 AS sort_col
FROM order_header
UNION
SELECT '1Forza WIP' AS client_id
, 2 AS sort_col
FROM dual
UNION
SELECT 'Total' AS client_id
, 3 AS
FROM dual
ORDER BY sort_col
, client_id
;If you don't want to display the extra column, see if you can tell your front-end tool not to display it.
In SQL*Plus, for example, you could say
COLUMN sort_col NOPRINTIf you can't do that, then compute the sort key in a sub-query, and don't include it in the main SELECT clause:
WITH got_sort_col AS
SELECT DISTINCT client_id
, 0 AS sort_col
FROM order_header
UNION
SELECT '1Forza WIP' AS client_id
, 2 AS sort_col
FROM dual
UNION
SELECT 'Total' AS client_id
, 3 AS
FROM dual
SELECT client_id
FROM got_sort_col
ORDER BY sort_col
, client_id
;Edited by: Frank Kulash on Mar 16, 2010 10:21 AM
Similar Messages
-
Using ORDER BY in UNION clause in cursor
Hi Everybody,
I have one situation and i need your help guys. I have to use ORDER BY in UNION of two queries and return value in cursor.
OPEN cursor FOR
SELECT ID, DESC,SID, ITID, SID_DESC
FROM (SELECT A.ID,
A.DESC,
B.SID,
NULL AS ITID,
B.SID_DESC
FROM TABLEA A, TABLEB B
WHERE A.ID = B.ID
order by A.SORTORDER asc,B.SORTORDER)
UNION
SELECT ID, DESC, ,SID,ITID, ITID_DESCRIPTION,
FROM (SELECT A.ID,
A.DESC,
NULL AS SID,
C.ITID,
C.ITID_DESC,
FROM TABLEA A,
TABLEC C
WHERE A.ID = C.ID
order by A.SORTORDER asc,C.SORTORDER)
I SORT ORDER is column in all three tables. TABLEA has unique number for each record as sort order. TABLEB has sortorder as 1 for each id. If id is two times then its 1 and 2 for each id. TABLEC has sort order as TABLEB, 1 for each id and if id is two times then it is 1 and 2 and id id is three times, it is 1, 2, 3.
I am not getting correct sorting as i cant use order by like this in UNION. Please let me know how i can handle this.
Thank you in advance to everybody.
I will really appreciate your comments and responses.Hi,
You can use ORDER BY in a sub-query, but there's usually no point in doing so, because the super-query won't necessarily preserve that order. You need to make the columns that you want to ORDER BY available to the main query, so that they can be used there.
Try this:
SELECT ID, DESC,SID, ITID, SID_DESC
FROM (
SELECT A1.ID,
A1.DESC,
B.SID,
NULL AS ITID,
B.SID_DESC,
A1.SORTORDER AS sortorder_1
B.SORTORDER AS sortorder_2
FROM TABLEA A1,
TABLEB B
WHERE A1.ID = B.ID
UNION
SELECT A2.ID,
A2.DESC,
NULL AS SID,
C.ITID,
C.ITID_DESC,
A2.SORTORDER AS sortorder_1
B.SORTORDER AS sortorder_2
FROM TABLEA A2,
TABLEC C
WHERE A2.ID = C.ID
order by SORTORDER_1 ASC -- ASC is the default, but it doesn't hurt to say it
SORTORDER_2This assumes that tableb.sortorder and tablec.sortorder have the same, or at least similar, data types. If not, explicitly convert sortorder_1 in one branch of the UNION to the type of sortorder_2 in the other branch.
Using the same alias to mean different things in the same query is just asking for trouble. I changed the table alias a (which was used in different places to mean two different things) to A1 and A2, each of which means only one thing.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using. -
Hi ,
i want to use "union" to combine 2 query results and also i need to apply order by clause in both queries,how i can achieve this
i.e
i wrote query like
select item_id from item_mst
where item_id <5
order by item_no
union
select item_id from item_mst
where item_id <10
order by item_no
But it is giving ORA-00933 error.
Please help me to over come this error.
Thanks in advanceYou cannot have an ORDER BY clause on each part of the union - there is only one ORDER BY allowed and that applies to the result of the union.
select item_id from item_mst
where item_id <5
union
select item_id from item_mst
where item_id <10
order by item_idI'm assuming you meant 'order by item_ID', not item_NO, since there is no item_NO column in the query. -
I'm new to P3. I need to manage a large 2 year public
works building construction schedule in downtown Los
Angeles, with numerous and frequent changes to the
schedule due to change orders, RFI's etc. Of course, these
changes result in increases/decreases to cost and time,
which need to be monitored and dealt with as part of the
overall project. Some say that fragnets are the best way
to insert these changes into the schedule. Some say
fragnets are problematic. I have no experience with
fragnets and I want to get off on the right foot. What
have you project managers and project engineers found most
effective for inserting and managing change order and RFI
items?Nat:
Thank you very much for
your response.
Your
explanation of fragnets was very useful. I will make a
point of saving and reusing repetitive groups of
activities. In my case, SOMD (slab-on-metal-deck) is
very repetitive. Also, exterior building finishes such
as plaster (exterior sheathing, lath, scratch coat,
brown coat, cure, finish coat, cleanup). Interior
finishes activities are also often identical from
floor to floor.
The issue with
RFI's is usually not so critical. I mentioned 1200
RFI's but relatively few impact the schedule and must
be coded in. But it is more than 48. In my case, the
most common reason for entering an RFI into the
schedule is when the
consultant/Architect/Engineer/State Agency exceeds the
contractually agreed upon time limit for response to a
design-related RFI, or his response is irrelevant
requiring a second round of RFI's to resolve the
problem (revise and resubmit for title-block
exceptions, for example, happens frequently). <br
/>
It is easy to ignore these delays,
and recording them in the schedule can really irritate
the consultant, but when they become a habit, the
cumulative impact on the schedule can be significant.
Therefore, I need to be able to track these RFI delays
effectively within the schedule. Of course, an RFI
always has a number that is tracked inside Expedition
as well.
The bigger problem is
Change Orders. As you know, when the Owner wants
something added to the work, or a problem in the
design results in an increase in the scope of work
(there are many other possible reasons of course) a CO
is requested. As a general rule, most change orders
contain both a cost increase as well as a time
extension. This time extension is the problem,
because, especially on public works projects, the
Owner/CM does not want to grant time an extension, and
even when they do, they will only grant it when it
impacts the critical path, and only after there is no
float remaining (you will see why this distinction is
important as you read further). The critical path
condition makes sense, but the idea that my float is
the Owner's to eat for his CO work is grating,
especially when facing potential LD's. <br
/>
To top it off, some Owners/CMs insist
that all time delays be dealt with at the end of the
project, when the actual time delay resulting from a
CO can be calculated, instead of simply estimated, as
is common practice (corresponding language is inserted
into the CO to that effect instead of a defined time
extension). My position is that if they refuse to
grant a time extension based on an estimate, then the
cost given in the CO, which is nothing more than an
estimate, should also be replaced with T&M, and
the budget be damned. Needless to say, that position
has not won me many friends in the trailer across the
way.
You might suggest that we
should refuse the extra work if a time extension is
not granted up front. If we did that, they would hit
our bond in a heartbeat. A contractor's lot in life
seems to be to make lawyers (Deo volente, may the burn
in hell) wealthy.
In the case
of the Owner/CM refusing to grant time for
non-critical path CO's, my position is that, while the
CO work may not be on the critical path this instant,
in many cases, the critical path can change
dramatically, sucking CO work into it that was
previously separated from it by weeks. That very thing
has happened on a school project located in a major
city we are doing.
The project
has extensive tubular secondary steel at the exterior
of the two buildings. This tube steel, ranging in size
from 4" diameter to 20" diameter curves around, and up
and down, the exterior of the structure. I do not
exaggerate when I say that it is more complicated than
a roller coaster. I will send pictures if you are
interested. It supports curvilinear LG framing, which
in turn supports a combination of plaster, brick
veneer and metal panels. Very phantasmagorical stuff.
Being a complicated 3-D arrangement of rigid steel,
the architect's drawings were incomplete, (we should
have expected that) and changed frequently (4 times)
during fabrication, resulting in detailing problems
and a two month delay in erection. Lots of unforeseen,
fit-scribe-cut-repeat of long, heavy, curved, twisting
pieces of long steel hanging from crane hooks has been
required.
We have recovered
most of that time, but only by doing a great deal of
out-of-sequence work.
As you
can imagine, this mess generated a ton of CO's, but
the Owner would not agree to grant time extensions
until the end of the project, and even then, only on
CO's that are provably on the critical path. When
combined with electrical changes impacting utility
buildings, cable pulls, elevators, manlift and even
exterior finishes, and then with added off-site work,
topped off by submittal-review delays by State
agencies, the critical path has flapped around like a
flag in the wind, with CO's going in and out of it. In
many cases, this means that a particular item of
ongoing CO work has delayed the critical path for a
period of time, but not for the entire duration of the
CO work. So calculating the exact impact of the CO
during the period it was on the critical path has not
been easy.
I anticipate there
will be huge disagreement about these calculations at
the end of the project when we have the "come to
Jesus" time/money resolution meeting with the
Owner/CM.
BTW, the CM always
insists that CO's be dealt with as fragnets, but that
doesn't always make sense because the nature of CO
work is often one-of-a kind, not repetitive stuff. But
he has fragnets on the brain, it seems, so we call
them fragnets to humor him.
<br
/>Anyway, as you can imagine, tracking the dynamic
(vs. static) effect of CO's on the schedule has been
difficult. I am almost tempted to try calculus methods
to calculate time consumed over time (if you get my
meaning). Any experience analyzing schedules using
differential equations? Someone must have done it
before....
Right now I am
using activity codes to track them, but I am wondering
if there is a better way.
<br
/>
I have other projects, without the
same delays, but similar Owner/CM mindset regarding
CO's
Now you know the long
story. Any suggestions?
<br
/>Stan -
Photos change order when burning to disc
I have created a separate album of photos that I want to burn to a CD. When I do so, some of the photos change order. I have tried to delete those photos and then re-add them to the album, but to no avail. I have also tried to change their date so that they are chronologically in the right order, but this doesn't help either. Any help would be truly appreciated. I want to give this CD to my father for Christmas. Thanks!!
ibook Mac OS X (10.4.7)Hi Tom,
You should be able to make a slidshow almost as easy as what you're trying to do right now... it'll take some pratice
Personally, I have both exported a slideshow from iPhoto to iDVD and also created a slideshow directly in iDVD, the latter is a better fit for what you're doing.
Open iDVD, create new project, name as you like and save, will auto open to work window, click on 'customize', pick a theme you like. Now click on 'Map' and in the customize pane click on 'Media'. In the media pane you have itunes, photos and movie, select photos... you're iPhoto library will appear along with all the albums you might have created and organized. Here's what makes it sweet, you can drag each album into the 'Map' Theme icon and it will automatically import and turn into a slideshow and take on the name of the album... to see your progess hit the Preview button... you'll have to do a little learning and tweaking, you can add music etc., but that's it, you made a slide show ready to burn to a dvd...
My suggestions would be to organize albums as you like, named appropriately and just have fun with it. You can save and go back and edit at a later date. Use the highlight and delete or cut options to remove etc etc etc...
You can burn project using the File > Burn DVD option or you can save the FINAL production use the File > Save As Disk Image option, and you can burn the DVD through disk utility which will give you more options on burn speed and buring at 1x speed may yield the best results...
Rick
iMac G5 iSight 20" - 30G iPOD in Slimming Black - Mac OS X (10.4.7) - HP Pav 15" WS and Toshiba Sat 17" WS LP's - Canon 20D & A620 -
Objects Changing Order for no Reason?
Hello, all...
I am using Captivate 2 to create software simulations and a
typical slide has many click boxes on it -- some that are "correct"
and will advance the simulation, some that are "incorrect" and will
provide specific remediation, and one that is full-screen to
provide remediation to a user who clicks anywhere else on the
slide. It is important that the correct click boxes stay in front
in the order and that the full-screen ones stay in back. I
typically use Bring to Front and Send to Back to put them in this
order.
The problem is that after I arrange things properly, save,
publish, close, and reopen the file, some of the click boxes will
have changed order. I have been able to find no rhyme or reason for
this, and naturally it causes a lot of work every time I need to
republish a file.
Has anyone else experienced this?Hi jkunrein and welcome to our community
I'm in the same boat as Larry. I've never seen this problem
occur on my own PC. This isn't to say it isn't happening to you,
only to say I've not encountered it either.
The purpose of my post here is to ask a question. And my
question is:
Why on earth are you using multiple "full screen" click
boxes? I might understand a single "full screen" click box that
would be used to catch something outside the areas of other smaller
click boxes that would be placed in front of the full screen one.
But for the life of me, I can't fathom why you would desire more
than a single click box that would cover the slide. The end result
is whichever click box was behind would never be dealt with.
Cheers... Rick -
Is it possible to change the OVERALL RESULTS to TOTAL?
Hi Guys,
When we select a field and in the properties of that field select the option Always Display Results row the query displays the total for that field but the text for the total is shown as OVERALL RESULTS. Is it possible to change that to TOTAL instead of overall results?
ThanksHi,
There is one SAP note available to change text of Result and Over all result to some other text. You can search that note in service.sap I dont have it with me.
But the yeast is if you change that it will be applicable to all the reports and it will change the text for all the reports. In order to change it at report level you may wanna use work-book. Not sure what is the solution if you are using web-templates.
Regards,
Akshay -
Change order of key figure is not working in Web report output (using WAD)
Hi,
We are using BI 7.0, release 701 and level 008. We are facing problem in WAD (web report output). When ever we do 'Select filter' for key figures and 'change the order' of key figures, it does not get reflected in new order. Though drag and drop of key figures is working.
Though same change order is working fine in Bex Analyser.
Kindly suggest some inputs.
Thanks.Hi,
On Which Service Pack are you on?WAD has this feature of re arranging the keyfigures in BI 7.0 for SPS 14...
Regards,
Bhagyarekha. -
Change order of line items in a financial document
Hello,
Is it possible to define the order of the line items in a financial document?
For example, I have always a discount line with a discount account in the first place and after this line, the customer line, and the bank account and I need to have the customer line in the fist place, is it possible to customize this order?Or is this standard?
Thank you very much!!Hi,
You can change orders in FInancial Document. Just open the document from Menu select Settings-> Layout--> Current.
change the position numbers as desired.
Regards,
JA -
Changing Order of Songs in Album-iTunes 12
Like the title says, how do I change the order of songs in a album? Before you could use get info and sort by track number.
ThanksHey Lando25,
I understand that you want to change order of songs that are playing in iTunes. This functionality should still be available to you, as confirmed in this article:
iTunes 12 for Mac: Edit song and CD information
https://support.apple.com/kb/PH19618
You may need to simply scroll in the information field in order to find the fields that you wish to edit. Thanks for coming to the Apple Support Communities!
Cheers,
Braden -
HT201317 change order of photos in photo stream album
How do I change order of photos posted in photo stream album?
Send a feature request to Apple via
http://www.apple.com/feedback/iphoto.html
and
http://www.apple.com/feedback/icloud.html
OT -
Help with fuzzy search (doesn't work if change order of certain 2 letters)
Hi,
need some help with fuzzy search. It's pretty simple - we use fuzzy search on varchar2 columns that contain first name and last_name. The problem is that i don't really understand why it can't find name in some cases.
Say i want to search for 'Taekpaul'. Then
where CONTAINS(first_name,'fuzzy(TAEKPAUL)',1) > 0 - works
where CONTAINS(first_name,'fuzzy(TAEKPALU)',1) > 0 - works (changed order of the 2 last letters)
where CONTAINS(first_name,'fuzzy(TEAKPAUL)',1) > 0 - doesn't work, finds 'Tejpaul' that is completely unrelated (changed 2nd, 3rd order)
How can i make it find 'Taekpaul' even if i search for TEAKPAUL? Is it related to index? Like Text index should be created with some different parameters?
Thanks!
Edited by: Maitreya2 on Mar 3, 2010 2:08 PMThanks, adding '!' worked :)
Do you know where i can read more about '!' and other special characters? I think i didn't see anything like that here: http://download.oracle.com/docs/cd/B14117_01/text.101/b10730/cqoper.htm#BABBJGFJ
I also started using JARO_WINKLER_SIMILARITY function that is actually better i think for what i do. But it's very buggy - sometimes Oracle crashes and kills connection when you try to use it.
Ahha, it's here: http://download.oracle.com/docs/cd/B19306_01/text.102/b14218/cqspcl.htm
So, ! is soundex. Whatever it means..
Edited by: Maitreya2 on Mar 5, 2010 12:14 PM -
How to look for SAP provided rules while changing orders ?
Hi:
we have a requirement to check for order type when the change order request ( in form of IDOC via EDI) is passed to SAP and the requirement is such that we can only accept certain order types like TA and reject order order type........from a very high level though process the idea is to check if SAP has certain pre build code that can be called before the va02 is called.....
I am new to sap and was told that we need to first look if SAP has a existing functionality if not then find user exit and customize it .....
my question is where does one look in SAP for such code ...or out of the box feature..........which can be called ....I understand if nothing is found we can write ABAP program to do this.....but I am puzzled as I do not now where to look and eliminate that such feature is not already provide ......
Thankscheck which FM you use to post your IDOC (like IDOC_INOUT_ORDCHG) and then check in this FM ... you'll find exits like 'call customer-function'.... I'm sure you'll find one which is called to validate data passed in your segment (where actual order type is passed).... or just use the one which works always after the order number is known and then just check your order type & raise error to fail IDOC so it will not even try to update your order.
-
How to change order data in APO
Hi,
I am keen to know on ways to change order data in APO say order category BI.....we want to change date by taking input from cif user exit APOCF006.We need this information for the ongoing project.
I know two options...1) using BAPIs 2) Not very sure about this option ...Function Module:/SAPAPO/OMORDER*CHANGE.
Could you please help to have better understanding on ways to change orders in APO?
Thank you
Best Regards
Nilesh PatilHello Rishi,
Thanks for your reply.
Demand node ofr purchase Ordre( BF) in SNP is Conrel( BI category). We want to change date( start date) at this demand node . We will get this date from R3 using say non cif method.
There are few ways to do it....
1) If we ignore Menas of Transport( so essentially transit time or lead time in tlane) in that purchase order and change this requirement date directly using purchase order save BAPI( requirement node) ......Question will system allow us to do so and even if it allows us to do so will it casue some problem( inconsistencies) later?
2) Second option I am thinking is...
For one product we maiantain GR processing time in product location master and this is considered while determining strat date of BI (Start date= Delivery date -GR procesisng time- means of Transport lead time - some other times ....). For this product let's say we have 100 Purchase Orders (BF). We have requirement that each of these POs should get separate treatment while calculating Start date. It means start date can be different for different POs and once we change it forcibly then it shoulkd not change unless we again change it forcibly.
We are thinking to change GR processing time at runtime wheneveer Purchase Order is changed. So if GR time in product location master is 1 day ....for different Purchase Orders different GR processing time can be considered. Say for Po1...its 2 day...for P2 its 4 day.
Or similar way we can change transit time as given in means of transport in tlanes.
Will appreciate your or anyone's comment
Thank you
Nilesh -
Change order of list items in sealed MP
Hi,
I have a MP that is sealed. It includes a list, but also list items exist in that sealed MP. I need to reorder the list. I have the unsealed MP and the seal used. Can i just edit the unsealed version, changing order in the XML code and increase ver. nr.
and if yes then how?Hi,
I did a test in my lab and just edited the xml version of the MP. I changed the numbers in ordinal to rearrange, incremented the version # plus resealed and imported.
<EnumerationTypes>
<EnumerationValue ID="IncidentPriorityList" Accessibility="Public" />
<EnumerationValue ID="Enum.cd7c7616b19745ffb646e0320ba85bb4" Accessibility="Public" Parent="IncidentPriorityList" Ordinal="0" />
<EnumerationValue ID="Enum.8ae91ca8f3a7439eb2941c4a1547908c" Accessibility="Public" Parent="IncidentPriorityList" Ordinal="2" />
<EnumerationValue ID="Enum.0d5e33cc41504a4eaf66b64b2dff3a2d" Accessibility="Public" Parent="IncidentPriorityList" Ordinal="1" />
</EnumerationTypes>
Maybe you are looking for
-
Why can't I open a new Tab with the "Plus" sign or "Command-T"?
If I want to open a New Tab, I either press "Command T" or select "New Tab" from the File menu, or click the little "plus" sign in my Tabs bar - - - right? None of them work. What am I missing?
-
How to make treetable transparent
hi, Does anyone have idea how to make the treetable transparent so that the background image can be shown? Pls provide sample code if possible,thanks!
-
I am developing MM Cube SRM Cube to create Procurement Analysis Reports using BW.What are the Fields or Tables from MM and SRM application to be used for developing the same .Jay
-
Linking position to mask path?
I know I can copy and paste a Mask Path to a layer's Position and vice versa. But is there a way to link them live with an expression? I think I'm running into a problem with too many dimensions in an array -- I'm trying to link a Light's 3D positio
-
Hello, I want to edit a special format of PDF document (map of town). This document is very large and long, and i want to divided the document in pages. But i don't want only put these pages up and under (page 1.2.3.4.5...) In fact i want two dimensi