MAX value / number of fields and PIVOT
I run a query against what would essentially be a db (Oracle 10 g) orders. I have 4 tables that I am querrying against.It is an abridged version of the result set.
CUS_ID ORD_NUM ACT_IND PRD_ID ORD_COMP_DT
794102 496342 N - New 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 4/4/2006
794102 709153 C - Change 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 4/10/2008
794102 741641 D - Discontinue 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 7/15/2008
794102 769121 D - Discontinue 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 3/3/2009
I tried to use the MAX (ORD_COMP_DT) and MAX (ORD_NUM) without success. I always get the same 4 rows returned.What I'm trying to accomplish is a result that will show me only the latest information relevant to the CUS_ID (which is unique for each PRD_ID).
SELECT max(ORD_COMP_DT) as COMP_DT,
max(ORD_NUM) as ORD
from table
My result set would be like:CUS_ID ORD_NUM ACT_IND PRD_ID ORD_COMP_DT
794102 769121 D - Discontinue 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 3/3/2009
With my limited knowledge, I guess it must be a subquery in my larger query against multiple tables. I looked through the forum and tried using some examples, but always without success.Update*-I managed to get the result that is close to what I want just by using the MAX function on ORD_NUM and ORD_COMP_DT and Group BY. However because there are several instances in the ACT_IND column my results exceed 1 line when I include this field. If at this stage, is - can anyone suggest how I can manage this area yet again that the latest ORD_NUM and ORD_COMP_DT?
Do not confuse the issue, but ultimately I'd like to be able to actually capture New oil fields and stop (PIVOT - I understand is not available on Oracle 10 g, which means another method) and those who, like this pivot:
CUS_ID NEW_ORD_NUM DISC_ORD_NUM PRD_ID NEW_ORD_COMP_DT DISC_ORD_COMP_DT
794102 496342 769121 1752AOC03GLVVNYXA5MDNRWCNYXA0MW 4/4/2006 3/3/2009
I'm sorry for the post disjointed - I tried to fix my problem before actually hitting the publish button, but I'm stuck.Thanks for the research.
G
Published by: GMoney on July 12, 2012 11:24
Published by: GMoney on July 12, 2012 11:27
Published by: GMoney on July 12, 2012 11:29
Hello
GMoney says:
... create table SR (DOCUMENT_NUMBER VARCHAR(10), ORDER_COMPL_DT VARCHAR(2), ACTIVITY_IND VARCHAR(4)); INSERT INTO SR VALUES('12345',to_date('04/04/2006 09:38:08', 'dd/mm/yyyy hh24:mi:ss'),'N'); INSERT INTO SR VALUES('23456',to_date('10/04/2008 14:21:28', 'dd/mm/yyyy hh24:mi:ss'),'C'); INSERT INTO SR VALUES('34567',to_date('15/07/2008 10:14:32', 'dd/mm/yyyy hh24:mi:ss'),'D'); INSERT INTO SR VALUES('45678',to_date('03/03/2009 14:55:55', 'dd/mm/yyyy hh24:mi:ss'),'D');
Good; you use correctly TO_DATE.
Why did you change the data type for irder_compl_dt to VARCHAR (2)?
Do all the joints, and any other filter you may need, inside the subquery were the ROW_NUMEBR is calculated, if not sooner.
The main request will do nothing except filter by rn (ROW_NUMBER results) and ORDER BY, if you want to sort the output.
WITH got_rn AS
(
SELECT ck.circuit_design_id
, sr.document_number
, ck.product_id
, sr.activity_ind
, sr.order_compl_dt
, ROW_NUMBER () OVER ( PARTITION BY ck.circuit_design_id
ORDER BY sr.document_number -- or sr.order_compl_dt
DESC
) AS rn
FROM ck
JOIN src ON ck.circuit_design_id = src.circuit_design_id
JOIN sr ON src.document_number = sr.document_number
-- WHERE ... -- If you need other filtering, put it here
)
SELECT circuit_design_id
, document_number
, product_id
, activity_ind
, order_compl_dt
FROM got_rn
WHERE rn = 1
ORDER BY circuit_design_id -- if wanted
;
If the largest number of document is always order_compl_dts later, then it doesn't matter which of these columns that you use in the ORDER BY clause analytical. Whatever it is, remember to specify DESCending order.
Tags: Database
Similar Questions
-
Check box to change the value of the field and reveal hidden text
Hello
I need to change a value in a field when you press a checkbox
the default value can be $ 10 in 'formfield1 '.
But when the checbox is checked, the value of 'formfield1' must spend $ 8
I also need a reval text function in "textfield2' of the text hidden to visible.
Is it still possible to combine in a box?
I found a code on the forum and changed it, but it does not work as expected, it affects the field, it shouldn't and it behaves a bit funny, here is the code to calculate.
I also tried to change the value of Off to On, but who has not reversed the procedure than I hoped.
Well its a start, maybe someone can understand a give me help on the way?
________________________________
custom for the discount calculation
var nDiscount = 2;
name of the Sub total field
var cSubTotal = "formfield1";
name of the non-Discount checkbox
var cbNonDiscount = "CheckBox1";
default value for the non-Discount
Event.Value = 10;
see if the purchase is with discount or not non-Discount
If (this.getField ("cbNonDiscount") .value == 'Off') {}
Event.Value = this.getField ("cSubTotal") .value - nDiscount;
}
put an end to a custom calculation
Ah, if you want the calculation to take place when the box is checked, use this:
If (this.getField (cbNonDiscount) .value! = "Off") {}
Instead:
If (this.getField ("cbNonDiscount") .value == 'Off') {}
-
Pdf form by e-mail to the value of the field and your real email address
I have a few questions, I am trying to solve and do not know how to proceed. I need the button submit to retrieve a value for a field that the user has filled in and I need to provide an email address.
I need to provide the text of the subject line of the message and add a value in a field that the user fills out.
I had these two elements to work based on scripts, I got on the Forum.
But I also need half superior (or the first page) of the form to send in a pdf file and the second half (or second page) to be an interactive form and a submit button that works similarly to the first Submit button.
How can I accomplish this? Apparently, I'm still not able to attach a copy of the form.
Thanks in advance.
MDawn
Hello
I would recommend a sample of Paul Guerette 'LockAllFields '. You can use this to lock all fields on page 1, before that the PDF file is saved and sent by e-mail. This will leave the objects on page 2 that interactive / "fillable inable".
I think Paul sample going on 'form1' in the function. You need to change 'page 1' so that it blocks only the objects on this page.
You won't be able to the PDF form is separated in two.
Good luck
Niall
-
Select a number of fields between one area and another
Hello
Is it possible to do a SELECT to show a number of fields of one field on the other.
without writing all the fields one by one?
For example, I have a table with the fields:
EMPLOYEE TABLE:
ID_EMPLOYEE NAME PHONE CAR AGE MARRIED
and I want to just do a SELECT that shows only the NAME to the AGE fields, but I don't want to
write to SELECT it all the fields one by one.
Is this possible?
Thank you very much.
Sorry for my English is not very good.Selim wrote:
HI, use the function below to get a list of the names of columns between 2 columns in a tableOr something similar to SQL...
SQL> ed Wrote file afiedt.buf 1 with t as (select '&table_name' as tn, '&min_col_name' as min_col_name, '&max_col_name' as max_col_name from dual) 2 ,cid as (select min(column_id) as min_col, max(column_id) as max_col 3 from user_tab_columns, t 4 where upper(table_name)=upper(tn) 5 and upper(column_name) in (upper(min_col_name),upper(max_col_name)) 6 ) 7 -- 8 select ltrim(sys_connect_by_path(c, ','),',') as cols 9 from ( 10 select row_number() over (order by column_id) as i 11 ,column_name as c 12 from user_tab_columns, t, cid 13 where upper(table_name)=upper(tn) 14 and column_id between min_col and max_col 15 ) 16 where connect_by_isleaf = 1 17 connect by i = prior i + 1 18* start with i = 1 SQL> / Enter value for table_name: emp Enter value for min_col_name: job Enter value for max_col_name: comm old 1: with t as (select '&table_name' as tn, '&min_col_name' as min_col_name, '&max_col_name' as max_col_name from dual) new 1: with t as (select 'emp' as tn, 'job' as min_col_name, 'comm' as max_col_name from dual) COLS ------------------------------------------------------------------------------------------------------------------------------- JOB,MGR,HIREDATE,SAL,COMM SQL>
which could just as easily be turned into a function.
Of course, it is usually fast enough just to do a describe on the table statement in SQL * more and use the copy/paste and a quick insertion of «,»
-
SQL, find the MAX value and placing it as a QVariant
I have a database that is loaded and defines the customerID as 0 which is ideal when the database is not be saved and restored, etc. The question I have is that I added the possibility to users to restore a backup in the app, and now I have to do a query to select MAX (customerID) so that there is no duplicate CustomerID when you add or save items. Here is the following code, I knew that I must settle, specifically the 0 highlighted in red. I need zero to be the new customerID max value:
int SettingsStorage::load(int& lastID, GroupDataModel *model) { // number of locations loaded. QSettings settings(m_author, m_appName); int loadedCount = 0; QVariant items; // Get the last customer id first. // ID's will be generated by incrementing this number // Note values coming from settings should be cast to the // required type. lastID = settings.value(m_lastCustomerIDKey, 0).toInt(); items = m_sda->execute("SELECT * from items ORDER BY datefield"); qDebug()<< "the ID" << items; // Load all the locations from the database. foreach( const QVariant& temp, items.value
() ) { Location *p; if (loadLocation(temp.value (), p)) { model->insert(p); loadedCount++; } } return loadedCount; } Ive tried the following, but it doesn't seem to do anything:
int SettingsStorage::load(int& lastID, GroupDataModel *model) { // number of locations loaded. QSettings settings(m_author, m_appName); int loadedCount = 0; QVariant items; // Get the last customer id first. // ID's will be generated by incrementing this number // Note values coming from settings should be cast to the // required type. QVariant endID = m_sda->execute("Select MAX(customerID) from items") lastID = settings.value(m_lastCustomerIDKey, endID).toInt(); items = m_sda->execute("SELECT * from items ORDER BY datefield"); qDebug()<< "the ID" << items; // Load all the locations from the database. foreach( const QVariant& temp, items.value
() ) { Location *p; if (loadLocation(temp.value (), p)) { model->insert(p); loadedCount++; } } return loadedCount; } Any help will be loved and marked solutions.
-Thanks in advance
I was wrong about executeAndWait(). Somehow, I decided that you use the SqlConnection object, but seems his SqlDataAccess. So disregard my previous post. Keep your execute method, but you must change your code to something like this:
QVariant endID = m_sda->execute("select max(customerID) as m from items"); QVariantList vlist = endID.value
(); QVariantMap vmap = vlist.first().toMap(); lastID = vmap["m"].toInt(&ok); So I changed your SQL query slightly and added "that m" so I will have something to refer later.
Then I cast QVariantList because it is where are the results.
Then because we know its going to be the only record, I took the 1st element in the list and converted to QVariantMap.
Last step is to get the maximum.
Should work this time
-
How to restrict a Min - Max value field
I have a form wih 8 areas where the user can enter the numbers. And a box of total auto calculates the values as the total sum.
But I want to restrict the total field as max value is 60.
When the max value is greater than 60, popup saying error
"Value must not exceed 60.
Mall clear fields (text1.value = "")
Thank you.
The custom calculation script could be something like:
Customized for total fields calculation script
(function () {}
var sum = 0;
An array of names of input fields
Call upon him = ['text1', 'text2', 'Text3', 'text4', 'Rem5', 'Text6', 'Text7', 'Texte8'];
Add up the values of the input fields
for (var i = 0; i)< afields.length;="" i="" +="1)">
sum += + getField(aFields[i]).value;
}
Set this field to the amount value, unless it is greater than 60
If (sum<= 60)="">=>
Event.Value = sum;
} else {/ / clears all the fields and the user to alert}
Event.Value = "";
resetForm (aFields);
App.Alert ("error goes here.", 3 ");
}
})();
Set the names of the fields in the table invoke him to match the names of the fields and to change the alert text.
-
How do I calculate that in the script? I have 3 domains. A field is a constant date mm/dd/yy. The second field is a digital number (1-120) and can be changed. The third field calculates two fields 1 and 2 in the summation and shown in mm/dd/yy.
You searched for ' add days?
You must write a custom for this JavaScript calculation because you cannot add a number any date. Also the date strings are not just a number, even if we can convert a given date in a number for that date that represents the time form a date date (Epoch). Witn this value, we can achieve them all kinds of date calculations and collect a little information about the date. JavaScirpt uses midnight on January 1, 1970 UTC for starting point or the date of the time. Its value is zero, and every millisecond increases the value of 1. When a date string is converted to the date object JavaScirpt we have access to many properties of the date and can use several methods to extract information or adjust the date object.
Field 1 is in the format "Date" with a format of "mm/dd/yy".
Field 2 is in «Number» format with 0 decimal.
Zone 3 is in the format 'None '. The custom calculation script applies to the formatting.
The custom for JavaScript calculation area 3:
var cField1 = this.getField("Field_1").valueAsString;
var cField2 = this.getField("Field_2").valueAsString;
Event.Value = "";
If (cField1! = "" & cField2!) = "") {}
Console.println (cField1 + "" + cField2);
calculate that if we as no null data;
var cDateFormat = "mm/dd/yy";
convert start date date object.
Kai var = util.scand (cDateFormat, cField1);
get the date of the month;
David var = oDate.getDate ();
Add field 2 number of days;
David = Number (nDate) + Number (cField2);
of being updated for the new date.
oDate.setDate (nDate);
Set the field to update formatting;
Event.Value = util.printd (cDateFormat, letter);
} / / end of data not null;
-
Change the number of decimal places according to the value of the field
Hello world
I'm doing a form using Adobe Acrobat.
I want a field that usually has only 2 decimal places, to have 4 decimal positions ONLY when necessary.
Example: If the value of the field is 3.53 that's fine, but if the value is 3,5346 I want to show him this.
I played around field properties and I realized that I need to use a custom format script. I don't know where to start, however. Can you point me in the right direction?
Thank you in advance.
I just threw together quickly and did not test, take is as a general guide. It is intended to be placed in a JavaScript to the document level and called from custom Format script of the field. You can not put it simply everything as the script to Format because of the way that Acrobat behaves when you do.
The point of the script is to calculate the number to use as the first parameter to the AFNumberFormant function, which is that Acrobat uses when configuring a digital format. I couldn't think of a clever name for the function, so I leave it to you:
function fmt1() { // Set the minimum number of digits to the right of the decimal var min = 2; // Get the field value, as a string var val = event.value; // Round to the nearest 10-thousand of a cent var rn = util.printf("%.4f", val); // Replace any trailing zeroes with nothing rn = rn.replace(/[0]+$/, ""); // Get the number of characters after the decimal var num = rn.split(".")[1].length; // Set to the minimum if appropriate if (num < 2) num = 2; // Use built-in formatting function AFNumber_Format(num, 2, 0, 0, "\u20ac", true); }
Call it like that in the case of the field Format:
fmt1();
If this isn't a calculated field, but the one who interacts with a user, you'll want to add a function with the swing, something like:
function keystroke1() { AFNumber_Keystroke(2, 2, 0, 0, "\u20ac", true); }
-
Get the Max values and average of the different cycles in the single channel
Hello
I'm trying to get the Max values and average of the single channel that has different cycles it contains. I tried to use commands such as Chnclasspeak3 and chnpeakfind, but they were not useful for me. What I need is the Max values and average of the different cycles numbers saved in the data channel.
Exampld if the string contains 5 numbers of repetitive cycles, then we must find the maximum values and the average of these 5 cycles in the single channel. Attached reference data. This is the .raw file and I have the plugin for it to use in diadem 11.1.
Kind regards
X. Ignatius
Hello, Ignatius,.
Sorry, it took some time to provide a replacement based on the script for the function. Please take a look at the attached script. I changed the script to use my function if the tiara-version is less than 12. My script function is not as fast and more stable than the implementation of tiara, but for now, it does the job
Andreas
-
the min and MAX values maintain their good values tia sal22
the min and MAX values maintain their good values tia sal22
Hi all
I have problems a little value to stay in their correct min and max values min and max.
Continue to change their values (up and down) trying to get the max value to only display the maximum value at a given time and the same for the min value. I looked at the examples max and min and it seems that it should be in a while loop
http://forums.NI.com/NI/board/message?board.ID=170&thread.ID=359822but I would add another while loop and if so put it in the loop for? or is there a better way to do it.
TIA sal22
Hi sal22,
I thought it was just one example you found somewhere, because it is called red rooster. See the attached example.
Mike
-
Hallo,
I want to double click on a line of an af:table to call a page that displays a form (based on a View object) with the details of the selected line.
I need to go to the second page the value of a field on the line that is selected on the first page.
How can I do this? In particular, how can I get the value of a field from the selected line? How can I call the second page on double-click on the af line: table?
Thank you
F.
Why would user, you need to pass a value of the line to the shape?
The framework selects the line you want to display in the form. All you have to do is to show the form with the selected line. It is the framework automatically as long as you use e vo even the same data control.
Timo
Post edited by: Timo Hahn
And the handling double-clicks is described here http://www.oracle.com/technetwork/developer-tools/adf/learnmore/56-handle-doubleclick-in-table-170924.pdf -
Total of fields and to change the font for values 0 color
Hi, I'm relatively new to scripting, and I have created a form that is used both as a PDF to fill and print. It's a decklist and I want to be able to total the fields for each specific type of map to display the toal in another area, and then add those fields for a total of bridge. I can easily accomplish this depending on the sum in Acrobat X using the but when printing the list empty to be used by players at an event the zeros print in total fields and confuses the younger players.
I would use a calculation script custom that totals fields and checks the total and also if it's zero changes the color of the font to white.
Any help would be appreciated.
Or you can put the code below in the validation.
If (event.value == 0) event.value = ";
-
How to enable and disable a button depending on the value of a field
Hello experts,
I enable and disable a button depending on the value of a field.
I did the following:
in a trigger of on_new_form_instrance I put the following
the problem is that it works but does not change when my header_status value is changed.begin go_block('OE_HEADER'); execute_query; IF :oe_header.status = 'BOOKED' THEN SET_ITEM_PROPERTY('CONTROL.ACTION',ENABLED,PROPERTY_FALSE); else SET_ITEM_PROPERTY('CONTROL.ACTION',ENABLED,PROPERTY_TRUE); end if; end;
You have to put the same code in when-validate-item trigger of: oe_header.status...
and I think that this code should be trigger after query
IF: oe_header.status = 'RESERVED' THEN
SET_ITEM_PROPERTY('CONTROL.) ACTION', ENABLED, PROPERTY_FALSE);
on the other
SET_ITEM_PROPERTY('CONTROL.) ACTION', ENABLED, PROPERTY_TRUE);
end if; -
compare a value to the range of values in the table and get the value of corr
Hi all
I'm a begineer and glued at one point.
I have a table that has 2 fields
number of days and the number of cards with values such as:
number of days number of cards 20 1
I have a SELECT query that returns the number of days, I need to get the number of cards based on the number of days.
40 2
60 3
As if the select returns 30 I should get 1 as the number of cards, if select returns 48 I should get 2 and so on.
Please help me
Thanks and greetingsSELECT MAX(num_of_cards) FROM your_table WHERE num_of_days <= X
-
Sort numerically a varchar2 container field '-' and tanks
I have a Field1 varchar2 (20) that contains values such as
2-14', 3-9', '1-1-2 T'
They should be sorted in the order
' 1 1-2 T '
2-14'
3-9'
I tried to use lpad (field1, 22, '0') but he left buffers at a given fixed length for the whole area and it does not work.
There is no fixed grammar for this field and it is possible that in the future some unexpected tank can appear in the field. For example, "[1-2]" "
But the query needs to work even if the sort is not correct.
Can someone please help?select field1,field2,field3...from table tab1, tab2...where ... order by field1;
Thank you.Hello
Sorry, I don't understand the sorting rules.
It looks like
(a) the string is divided into a number of secondary channels by hyphens.
(b) sorting through secondary channels in the order, i.e. the substring n matter only if there is equality of strings 1 through n - 1.
(c) strings composed entirely of numbers preceded by secondary channels who have other characters
(d) secondary digital channels are classified as numbers, that is, '1' and '01' are the same, but comes from '1' before ' 03 "
(e) other substrings are classified as stringsUnder these rules, the two identical channels ' 1 - 1 - R 'would come after the strings that start with 1-01 - 1-'.
Other than that, the following query is what you asked:WITH cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 1 + ( SELECT MAX ( LENGTH (txt) - LENGTH ( REPLACE ( txt , '-' ) ) ) FROM table_x ) ) , got_sub_txt AS ( SELECT id , txt , n , REGEXP_SUBSTR ( txt , '[^-]+' , 1 , n ) AS sub_txt FROM table_x JOIN cntr ON n <= 1 + LENGTH (txt) - LENGTH (REPLACE (txt, '-')) ) , got_sort_key AS ( SELECT got_sub_txt.* , SYS_CONNECT_BY_PATH ( CASE WHEN REGEXP_LIKE ( sub_txt , '[^0-9]' ) THEN '2' || RPAD (sub_txt, 10) -- Magic Number ELSE '1' || LPAD (sub_txt, 10, '0') -- Magic Number END , '-' ) AS sort_key FROM got_sub_txt WHERE CONNECT_BY_ISLEAF = 1 START WITH n = 1 CONNECT BY n = PRIOR n + 1 AND id = PRIOR id ) SELECT id , txt FROM got_sort_key ORDER BY sort_key;
This requires that each substring will be (at most) 10 characters long. That's what the 'magic number' 10 in got_sort_key of the subquery. You can change this to whole m that you like.
The only limit is the number of subkeys is that they must all fit in a VARCHAR2 4000 characters, so the limit is 4000 / (m + 2) (e.g., 333 when m = 10).For this solution, you need a unique identifier (id in the example above) for each line. You don't need to display this identifier in the SELECT clause.
If txt itself is unique, it can be used as the identifier.
Maybe you are looking for
-
On 22 September, I tried in vain to install MacOS 10.12 Sierra. He failed during installation with a message despite the 198 GB available disk space. Today, I tried again, but the Ap store reports that Sierra has been downloaded. If yes how to either
-
Portege M400: Where should I put the PIN for the Sim Card?
I had the Tablet, I got the SIM... I turned on the wireless wan. Now, where should I put the pin code of the card? See you soon,.Miguel
-
Why can not download album art more?
I used to be able to download my CD collection to iTunes and was able to download album art. However, in the last months (maybe since my last update of iTunes), it has not have been possible. Does anyone know how to fix this?
-
keep getting dial ras in windows it can not conect wireless how to fix
Keep ras dial in windows this on my netbook can not conect wireless how to fix or there at - there no virus program to do a scan of all the programs I checked is not compatible win this
-
I use the property system DAQmx node to read all the data the scale for global for thermocouple in MAX I use MAX 4.4, LV7.1.1, with a SCXI chassis in a PXI-1050 chassis. It seems to read the properties very well on first run. However, if you then cha