Select first field from column in group value
Hello,
I need to return the first row of data grouped by the first field (Visit ID) in multi-column table:
VisitID AdmitDate Unit Room OrderCode
001041 2014-08-01 2E 202 SWCC
001041 2014-08-01 2E 202 NULL
006811 2014-08-01 2E 204 SWCC
008815 2014-08-01 2E 206 NULL
004895 2014-08-01 2E 207 SWFA
004895 2014-08-01 2E 207 SWCC
004895 2014-08-01 2E 207 NULL
To return:
001041 2014-08-01 2E 202 SWCC
006811 2014-08-01 2E 204 SWCC
008815 2014-08-01 2E 206 NULL
004895 2014-08-01 2E 207 SWFA
I currently have a group by clause with all field names; and have tried max on the OrderCode in the select that doesn't work, and FIRST isn't recognized in SSL server. Do I need a subquery (if so, how as I'm newer to writing SQL) or what is another
solution? Thank you.
create table t (VisitID varchar(50), AdmitDate date, Unit varchar(50),Room varchar(50),OrderCode varchar(50))
insert into t values ('001041' , '2014-08-01' , '2E' , 202 , 'SWCC' ),
('001041', '2014-08-01' , '2E' , 202 , NULL),
('006811' , '2014-08-01' , '2E' , 204 , 'SWCC'),
('008815' , '2014-08-01' , '2E' , 206 , NULL),
('004895' , '2014-08-01' , '2E' , 207 , 'SWFA'),
('004895' , '2014-08-01' , '2E' , 207 , 'SWCC'),
('004895' , '2014-08-01' , '2E' , 207 , NULL)
--To return:
--001041 2014-08-01 2E 202 'SWCC'
--006811 2014-08-01 2E 204 'SWCC'
--008815 2014-08-01 2E 206 NULL
--004895 2014-08-01 2E 207 'SWFA'
select VisitID,AdmitDate,Unit,Room , max(OrderCode) as OrderCode from t
group by VisitID,AdmitDate,Unit,Room
Order by VisitID
--Or
select VisitID,AdmitDate,Unit,Room ,OrderCode from (
select VisitID,AdmitDate,Unit,Room ,OrderCode, Row_number() Over(Partition By VisitID Order by OrderCode DESC) rn from t
)t
WHERE rn=1
Order by VisitID
drop table t
Similar Messages
-
Selecting first char from column
In my qeury below i would like to select the first character from the column other_party_number. How can i do this? The left function does not seem to work
in pl/sql. I get an error statinf invalid identifier. Can anyone please help? Thanks
select call_date, left(other_party_number, 1) as number
from ccwebcf.calls_archiveHallo,
why do you think, that LEFT must work in SQL ? :-)
Dmytro,
Probably because LEFT works in other languages and other incarnations of SQL. Not everyone is tied to Oracle you know. ;-)
Oh look, if I run the SQL on an ingres database...
select left('blushadow',3) as name
name
bluMwuhahahaha!
:) -
How do you select individual items from within a group?
Hi, All.
New poster. Forgive me if I miss any forum etiquette.
Currently using Indesing CS6 on Mac Osx 10.7.4
I'm a relatively recent convert to Indesign from Quark, and one thing I seem to have continual problems with is selecting individual items from within a group.
For example I will have a grouped item, such as price marker that is comprised of several individual items, some text boxes, some rectangles.
I find there is no way to select a rectangle that is currently placed behind a transparent text box without ungrouping the entire item - which isn't really an option.
The select options (slect next item below etc. just don't work)
For any Quark users out there, the equivalent command I'm looking for is the cmd+opt+shift click through, which just worked absolutely perfectly.
I have scoured the internet and forums looking for an answer for this, as I assumed it must be my own lack of knowledge, but I can't find an answer.
Any help much appreciated.
ThanksHi, winterm.
Thanks for the super quick repsonse. Unfortunately that hasn't seemed to have helped me.
That works fine as long as the grouped items are overlapping or apart, but not when items are entirely behind another item (ie, no part protruding from the group)
The problem is that if I double click to try and get through a text box to an item that is entirely behind it, then it just switches into text edit mode for the top text box.
If it helps, could you imagine a transparent text box that is 20x20 with red rectangle centred beneath it that is 10x10. If the 2 items are grouped I cant find any way to select through to the red rectangle without first ungrouping the two.
Am I going mad? -
How to compare two fields from two different groups
My RTF template is like this.
GROUP A
Field 1 Field 2 Field 3 (Display in table)
GROUP B
**Condition
Display Fields from B
end GROUP B
end GROUP A
But I need the following condition to be added at the place (** Condition)
IF A.Field1 = B.Field1
Display fields from B
END IF
end Group B
end Group A
Please help, if anyone has come across such a situation.
Thanks,
AnandYou can use variables to store the A.field1 value and then compare it against B.Field1.
Take a look at this post for an example: https://blogs.oracle.com/xmlpublisher/entry/formatting_concatenated_dataso
Thanks,
Bipuser -
Call Transaction and fill a select-options field with more than one value?
Hello everybody,
how can I fill a select-options field with more than one value.
Here is the code example:
CLEAR: GT_BDCDATA, GS_BDCDATA.
GS_BDCDATA-program = 'RHALEINI'.
GS_BDCDATA-DYNPRO = '1000'.
GS_BDCDATA-DYNBEGIN = 'X'.
APPEND GS_BDCDATA TO GT_BDCDATA.
CLEAR: GS_BDCDATA.
GS_BDCDATA-FNAM = 'PCHOTYPE'.
GS_BDCDATA-FVAL = 'P'.
APPEND GS_BDCDATA TO GT_BDCDATA.
CLEAR: GS_BDCDATA.
LOOP AT gt_hrobjinfty INTO gs_hrobjinfty.
GS_BDCDATA-FNAM = 'PCHOBJID-LOW'.
GS_BDCDATA-FVAL = gs_hrobjinfty-objid.
APPEND GS_BDCDATA TO GT_BDCDATA.
CLEAR: GS_BDCDATA.
ENDLOOP.
CALL TRANSACTION 'PFAL' USING GT_BDCDATA MODE 'A'
MESSAGES INTO GT_MESSAGES.
THX.Hi,
Please refer the code below:
*Code used to populate 'select-options' & execute report
DATA: seltab type table of rsparams,
seltab_wa like line of seltab.
seltab_wa-selname = 'PNPPERNR'.
seltab_wa-sign = 'I'.
seltab_wa-option = 'EQ'.
* load each personnel number accessed from the structure into
* parameters to be used in the report
loop at pnppernr.
seltab_wa-low = pnppernr-low.
append seltab_wa to seltab.
endloop.
SUBMIT zreport with selection-table seltab
via selection-screen.
Thanks,
Sriram Ponna. -
Selecting desired fields from extract structure to datasource in CRM
hi guys... coming back to this forum with new problem...
how are you guys...
i'm using ds 0CRM_SALES_ACT_1 in CRM to extract activities related data...
by standard this data source is not supplying some fields which i needed... but when i checked in 'roosfield' table and even in extract structure 'CRMT_BW_DS_ACTIVITY' it is showing the those fields which i required...
how can i get these fields to data source...
in LO its like...we can select required field from extract sturcture right???
is there any procedure do same with CRM data sources...
thnaking you...
regards...
nithin
Message was edited by: nith lHi,
If the fields are available in ES but not available in DS , then we can Modify the table ROOSFIELD. But, I think, this is some what rude mothod.
Before doing this, It is better to Raise a OSS. They may come out with some SP upgradation.
Search this forum with ROOSFIELD.
With rgds,
Anil Kumar Sharma .P -
How to fix the first field or column in classical report while scrolling
i want to know, how to fix the first field or column in classical report while scrolling
horizontally. the first should be constant when i scroll the report horizontally .
please help me.
it's urgent.Hi,
Suppose your first field is itab-matnr.
WRITE :/ itab-matnr.
SET LEFT SCROLL-BOUNDARY.
WRITE :/......."Remianing fields -
How to select and field from an table with similar value
Hi Gurus,
I got an requirement where i need to capture some values from an table whose value start with "vmr*"
could anyone tell me the syntax to be used with this?
My table contains valies like "lrt", "vmr'" nut i need only values starting with "vmr"*
RaviHi,
In where clause, you can write,
where field like 'vmr%'.
Hope this helps.
Reward if helpful.
Regards,
Sipra -
Select first and last records in grouped results - Oracle 11g
Say I have the following information in an Oracle 11g table:
Qty
Production order
Date and time
20
00000000000000001
12-JAN-14 00:02
20
00000000000000001
12-JAN-14 00:05
20
00000000000000001
12-JAN-14 00:07
20
00000000000000001
13-JAN-14 00:09
30
00000000000000002
12-JAN-14 00:11
30
00000000000000002
12-JAN-14 00:15
30
00000000000000002
12-JAN-14 00:20
30
00000000000000002
14-JAN-14 00:29
I would like to write a query that would return the following:
Qty
Production order
First
Last
80
00000000000000001
12-JAN-14 00:02
13-JAN-14 00:09
120
00000000000000002
12-JAN-14 00:11
14-JAN-14 00:29
That is, the sum of the Qty column grouped by Production order, and the date/time of the first and last records for each Production order.
I came up with a query that yielded this result:
Qty
Production order
First
Last
80
00000000000000001
12-JAN-14 00:02
14-JAN-14 00:29
120
00000000000000002
12-JAN-14 00:02
14-JAN-14 00:29
Which means that the First and Last columns show the overall first and last date / time of the whole table. Please note that this is a dummy table. Sorry I am now allowed to write the actual query
I came up with since work policies do not allow me to share it. Also, I tried with windowing functions such as rank()and row_number() but my user does not have enough privileges to do so.
Any help or hints will be greatly appreciated.Due to the fact that Oracle does not record the rows in any particular order, it would be wrong that the "first date" would be the first row processed by the query.
Therefore you would have to supply some other column if you do not want to consider the table as ordered by date.
Also, any analytical functions will need you to supply the "order by" and if its the date, then just a simple query will do:
SQL>WITH Tab1 (Qty, Production_Order, Pdate)
2 AS (SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:02', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
3 SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:05', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
4 SELECT 20, '00000000000000001', TO_DATE ( '12-JAN-14 00:07', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
5 SELECT 20, '00000000000000001', TO_DATE ( '13-JAN-14 00:09', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
6 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:11', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
7 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:15', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
8 SELECT 30, '00000000000000002', TO_DATE ( '12-JAN-14 00:20', 'DD-MON-YY HH24:MI') FROM DUAL UNION ALL
9 SELECT 30, '00000000000000002', TO_DATE ( '14-JAN-14 00:29', 'DD-MON-YY HH24:MI') FROM DUAL)
10 SELECT SUM ( Qty), Production_Order, MIN ( Pdate), MAX ( Pdate)
11 FROM Tab1
12 GROUP BY Production_Order
13* ORDER BY Production_Order
SQL> /
SUM(QTY) PRODUCTION_ORDER MIN(PDATE) MAX(PDATE)
80 00000000000000001 12-Jan-2014 00:02:00 13-Jan-2014 00:09:00
120 00000000000000002 12-Jan-2014 00:11:00 14-Jan-2014 00:29:00 -
Selection-screen (field from .Include structure)
Hi all,
I have a selection screen with several select-options. One of the select-option is
select-options: s_vornr for afvc-vornr.
Where 'vornr' is a .Include structure field in the table 'afvc'. Now my question is, in selection screen when I click on the box for this particular select-option I dont see the circle(from where we can select the existing input values) at the end of the box.
Why is it so and how can get that circle option at the end of the box by sticking to the same table and field(afvc-vornr).
Waiting for your help.
Thankshi,
the field do not have nay value range with it.
you can put the F4 help by using
At Selection-Screen on Value-request <select-option>. event.
e.g.
DATA : rt_values TYPE STANDARD TABLE OF type_values,
rs_values TYPE type_values,
rt_fields TYPE STANDARD TABLE OF type_fields,
rs_fields TYPE type_fields.
CLEAR : rs_values,rs_fields.
REFRESH : rt_values,rt_fields.
Creation of selection list
rs_fields-tabname = 'AFVC'.
rs_fields-fieldname = 'VORNR
rs_fields-selectflag = ' '.
APPEND rs_fields TO rt_fields.
SELECT vornr form AFVC
INTO TABLE t_vornr.
SORT t_vornr.
DELETE ADJACENT DUPLICATES FROM t_vornr.
LOOP AT t_vornr INTO s_vornr.
rs_values = s_vornr-vornr.
APPEND rs_values TO rt_values.
CLEAR rs_values.
ENDLOOP.
FUNCTION 'HELP_VALUES_GET_WITH_TABLE' EXPORTING
fieldname = 'AFVC'
tabname = 'VORNR
titel = 'Counting
IMPORTING
select_value = <select-opion>
TABLES
fields = rt_fields
valuetab = rt_values.
amit
Message was edited by: Amit Khare -
Select Distinct Fields from non related table
Hi Experts,
I have to fetch Distinct Fields from table zdcxy along with the fields from the table zvend but there is no primary key forigen key relationship also if I wanted use join condition. I need to move fields from both the table into output file and 1 part I implemented but I am unable to do second part plz any body can help me its argent. below I pasted part of code along with two requirements.
1.Select all data (Location - LIFNR, Descr u2013 ZPLTNAMEC, CJI_CUSTOMER u2013 CJI customer flag) from ZVEND table.
2.Select all distinct DCs and BUs from zdcxy table.
SELECT * FROM ZVENDPLT INTO CORRESPONDING FIELDS OF TABLE IT_VENDPLT.
*select distinct zdc from zdcxy into corresponding fields of table it_map.
*select distinct zbu from zdcxy into corresponding fields of table it_map.
IF SY-SUBRC = 0.
LOOP AT IT_VEND.
MOVE : IT_VENDPLT-LIFNR TO IT_TAB-FIELD1,
IT_VENDPLT-ZPLTNAMEC TO IT_TAB-FIELD2,
IT_VENDPLT-CJI_CUSTOMER TO IT_TAB-FIELD3,
CONCATENATE :IiT_TAB-FIELD1 IT_TAB-FIELD2 IT_TAB-FIELD3 IT_TAB-FIELD4
INTO IT_LOAD-RECORD SEPARATED BY SEPARATOR.
TRANSFER IT_LOAD TO OUT_FILE.
ENDLOOP.
Can any body explain me hw to fetch DC and Bu from the table zdcxy and keep in the same loop of it_vend.
Second thing is that I need to give information about records into second output file hw to do that means I opened one more file and I am unable to move the record history there plz help me.
Thanks in advancePlz any body can help me it's argent.
Thanks
Basu -
Dear all experts,
I am able to populate all fields data from database table, using dynamic table creation.
eg,
SELECT * FROM (w_tabname) INTO TABLE <t_itab>.
where w_tabname is the table name given by the user, and t_itab is field symbol.
but some requirement is like that i need to pick up only few fields, <b>which user will give at the runtime.</b>
<b>I can</b> take those fields from file into any internal table,
but the problem is that instead of <b>select *</b>, i need to put selected the fields given by user.
i have tried with field symbol, it is not working (as per my knowledge.)
do i need to create any structures dynamically ?
Can anybody please help in this regards ?
Your help will be surely rewarded with points.
Waiting for reply..
Regards
VinayHi Vinay ,
Adding to the below code , you can use some more fields in the select stmt as below:-
REPORT ychatest.
PARAMETERS : p_field1 LIKE dd03l-fieldname,
P_field2 LIKE dd03l-fieldname,
p_table LIKE dd03l-tabname.
FIELD-SYMBOLS : <fs> TYPE STANDARD TABLE.
SELECT (p_field1) (p_field2) ( FROM (p_table) INTO TABLE <fs>.
Now p_field1 & p_field2 belong to the same table since you have give the user to enter only one table name.
This should work fine.
please try & let me know .
Thanks & Regards,
Daniel -
Selecting Multiple fields from fillable form in Adobe Reader
I created a form in Adobe Pro, and want to be able to select multiple fields to cut and paste the results in other parts of the form.
Does anyone know of a way to do this?
I would appreciate any help! ThankyouGo to Form Edit mode, and then you can select multiple fields either in the Fields list, or on the page itself (using Ctrl), or by holding down the mouse and dragging the selection square over them. Then just Ctrl+C and Ctrl+V in the other page, and you'll get copies.
Edit: This can only be done in Acrobat, though. Your title talks about Reader but you post is about Acrobat... -
How to select a field from view
Hai All
This is my view name mtl_item_flexfields mif
i can able to select a single column Ie Inventory_item from view when i use this
Select inventory_item from mtl_item_flexfields mif.
But i not able get the values when i use this select statement
SELECT organization_code,
item_number,
mif.organization_id,
COUNT(*)
FROM mtl_item_flexfields mif,
mtl_parameters mp
WHERE mif.organization_id = mp.organization_id
AND mif.organization_id IN (87,85)
GROUP BY organization_code,
item_number,
mif.organization_id
HAVING COUNT(*) > 1
ORDER BY 1,2;
Thanks & Regards
SrikkanthHello Srikkanth,
The query you posted cannot return the inventory_item column because that column isn't part of you GROUP BY clause.
If you need to see the inventory_item column, you should either include it in your GROUP BY clause (but I doubt that's the right thing to do in this case) or, you need to apply an aggregation function to the inventory_item column, such as MAX or MIN (this may be appropriate in this case but, without seeing any data, can't really tell).
The GROUP BY limits the fields you can select to be either, included in the GROUP BY clause or, arguments of an aggregation function whose result is driven by the GROUP BY clause. In any other case, you'll get message complaining about the field not being part of a group by group.
HTH,
John.
P.S: put code (like the select you posted) and data enclosed in [ code ] <your code here> [ / code ]
(without the spaces), that will format the code nicely, like this
nicely formatted code herewhich makes it much easier to understand.
Edited by: 440bx - 11gR2 on Aug 13, 2010 5:44 AM - added "" suggestion -
Auto insert values to addition fields from a comma seperate value input?
I pray someone (Gunter :) ) knows how to do this or perhaps a better approach.
I have a google map api geocoding application that I created by following some sample files from the google api documentation. Works really well.
It gets the address information from an address field that has its values put in this format
"Street# Street, city, state/province" So... it would like like "123 fake ave, toronto, ON"
It is able to generate the longitude and latitude perfectly. How ever on the front end I would like the user to pull down show me based on just the city.
so.. show me "New york" or "Bowling green"... I was thinking of adding a city field into my table to facilitate this. It just seems redundant since the user already is going to put the address (which includes the cityname) above in the format I detailed. This is so the geocoding works.
So in the admin section when they add a new record is it possible to have some hidden fields that take the second comma seperated value (which would be the city)from the "address form field" (which is formatted with commas liek above) and input it into my "city column" in my table ?
any help of guidance is greatly appreciated, as alwaysHi Kevin,
PHP´s function "explode" (http://de2.php.net/explode) would allow you to split a comma separated string and echo the individual substrings wherever you want, however...
is it possible to have some hidden fields that take the second comma seperated value
...it seems you´d like to have the hidden fields "value" attribute dynamically updated based on the selected menu item, correct ? This will be much more complicated, as you´ll need some custom javascript to make this happen.
Cheers,
Günter Schenk
Adobe Community Expert, Dreamweaver
Maybe you are looking for
-
This is really frustrating, I've been trying to get my songs back for hours
-
Used Iweb to upload to ftp but now all my mobileme sites show up on ftp
I created a website on Iweb, then uploaded to Mobile me for final drafting process. When the client was satisfied, I moved the website to their designated ftp server using Iweb. Now, however, all the other websites I've been creating on Iweb and uplo
-
Hi, can I get a modified bios with the above swaps please? (swap FN with Ctrl, Left Alt with \ [left of spacebar], and Insert with Delete) My MOBO model is MS-1683. My laptop is the A6000-029US. Thank you.
-
Extend a non Airport wireless network with Airport Express
I want to use an Airport Express to extend a wireless network which is not an Airport network. The wireless is being provided by a wireless router. I tried setting up WDS, but that requires a wireless network. How do I extend the wireless network wit
-
Same MPEG-2 encoder in AME and Squeeze?
Can anyone tell me if the Mainconcept MPEG-2 encoder used in AME CS 5.5 is the same encoder as the MPEG-2 encoder in Squeeze 8? I'm evaluating Squeeze, more or less, to see if helps produce a better DVD from an HD project. Thanks...Ben