[8i] need help prevent a value being returned sometimes function LAG...
Note: I'll have to deal with a database 8i on this one...Here is a simplified table & data:
CREATE TABLE steps
( item_id CHAR(25)
, ord_nbr CHAR(10)
, sub_nbr CHAR(3)
, step_nbr CHAR(4)
, start_date DATE
, finish_date DATE
);
INSERT INTO steps
VALUES ('A','0000000001','001','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','001','0020',TO_DATE('01/03/2011','mm/dd/yyyy'),TO_DATE('01/03/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','001','0030',TO_DATE('01/05/2011','mm/dd/yyyy'),TO_DATE('01/06/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0010',TO_DATE('01/01/2011','mm/dd/yyyy'),TO_DATE('01/02/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0020',TO_DATE('01/04/2011','mm/dd/yyyy'),TO_DATE('01/04/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('A','0000000001','002','0030',TO_DATE('01/06/2011','mm/dd/yyyy'),TO_DATE('01/07/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('B','0000000002','001','0005',TO_DATE('01/10/2011','mm/dd/yyyy'),TO_DATE('01/12/2011','mm/dd/yyyy'));
INSERT INTO steps
VALUES ('B','0000000002','001','0025',TO_DATE('01/18/2011','mm/dd/yyyy'),TO_DATE('01/19/2011','mm/dd/yyyy'));
The actual data are the result of a query and has about 200K lines, but this should be enough to solve my problem... It contains a list of commands and the steps that each order has to pass before a product is finished. There is also the date of beginning and end for each step.My ultimate goal is to be able to calculate the product time (days) expected between steps. My first step to get what was:
SELECT s.*
, LAG(s.finish_date) OVER (
ORDER BY s.item_id
, s.ord_nbr
, s.sub_nbr
, s.step_nbr
) AS last_step_finished
FROM steps s
This allows me to bring to the date of completion of the previous stage, while in the next level of the query, I get the difference between the previous step finishing and the present stage from give me the waiting time.The only problem is, I need for the query return null for the LAG function if the line is the first step in an agenda - a single order is given by ord_nbr + sub_nbr - because I won't be calculate the time between the end of another way and the beginning of another. I will assume that there are no queues in any order. So, I guess I could return NULL at this level, or at a higher level, simply ignore the column last_step_finished if I determine that the rank be the beginning of an order, but whatever it is, I have some difficulty to reconstruct the code to determine if a line is the first step in an order.
My first thought is that the solution will look something like:
SELECT s.*
, CASE
WHEN --we're on the first step of an order
THEN NULL
ELSE LAG(s.finish_date) OVER (
ORDER BY s.item_id
, s.ord_nbr
, s.sub_nbr
, s.step_nbr
)
END AS last_step_finished
FROM steps s
Hello
Thanks for being so clear on your version and display the sample data; This is really useful!
Don't forget to post the exact results you want from these data.
You don't want to ORDER BY all these columns; you want to PARTITION BY som of them, instead, like this:
SELECT s.*
, LAG (s.finish_date) OVER ( PARTITION BY s.item_id
, s.ord_nbr
, s.sub_nbr
ORDER BY s.step_nbr
) AS last_step_finished
FROM steps s
The output of this product that is:
ITEM_ID ORD_NBR SUB STEP START_DAT FINISH_DA LAST_STEP
------- ---------- --- ---- --------- --------- ---------
A 0000000001 001 0010 01-JAN-11 02-JAN-11
A 0000000001 001 0020 03-JAN-11 03-JAN-11 02-JAN-11
A 0000000001 001 0030 05-JAN-11 06-JAN-11 03-JAN-11
A 0000000001 002 0010 01-JAN-11 02-JAN-11
A 0000000001 002 0020 04-JAN-11 04-JAN-11 02-JAN-11
A 0000000001 002 0030 06-JAN-11 07-JAN-11 04-JAN-11
B 0000000002 001 0005 10-JAN-11 12-JAN-11
B 0000000002 001 0025 18-JAN-11 19-JAN-11 12-JAN-11
If this isn't what you want, move some of the columns of the PARTITION BY clause from the ORDER BY clause.
PARTITION OF x, y, z is the analytical consideration of the aggregation GROUP BY x, y, z. This means that each separate combination of x, y and z will be considered to be a clean world, which do not interact with other values of x, y or z. On the first line of each partition, LAG return the NULL value, exactly as you wish.
Sorry, I don't have Oracle 8 to test, but I'm sure that LAG has not changed since Oracle 8.1.
Moreover, the CHAR data type is nothing trouble. Use rather VARCHAR2.
Tags: Database
Similar Questions
-
Need help: not prepared statement to return the value:
Hi refugees,
In LICS, prepared statement does not return any value...
This is the code...
String p_person_id = pageContext.getParameter ("person_id");
Connection Conn = pageContext.getApplicationModule (webBean) .getOADBTransaction () .getJdbcConnection ();
String payment_query = "select max (payment_date) in the xxbdf_payslip_detail_mv where assingment_id = (select assignment_id from the people_reporting_info where person_id ' + p_person_id + ') ';
PreparedStaement stmt = stmt.executeQuery ();
ResultSet rs = stmt.executeQuery ();
While ((rs! = null) & & RS.) Next
{
java.sql.Date sql_date = rs.getDate (1);
SOP (SQL_DATE)
/ * I tried this also * /.
java.util.Date util_date = rs.getDate (1);
SOP();
String string_date = rs.getString (1);
SOP();
}
and I have to format the date as "DD-MM-RRRR.
Please give your valuable suggestions refugees...
Thank you
Jaya
Jaya Hey,
Write the code below in the PR
Code for the prepared statement
String PaymentData;
String p_person_id = pageContext.getParameter ("person_id");
System.out.println ("The person Id is" + p_person_id); check the id of the person should not be null.
try {}
Connection Conn = pageContext.getApplicationModule (webBean) .getOADBTransaction () .getJdbcConnection ();
String query = "select max (payment_date) in the xxbdf_payslip_detail_mv where assingment_id = (select assignment_id from the people_reporting_info where person_id ' + p_person_id + '); '
PreparedStatement stmt = conn.prepareStatement (Query);
ResultSet = stmt. ExecuteQuery();
While (resultset.next ())
{
PaymentData = (String) resultset.getString("payment_date").toString ();
}
Conn.Commit ();
}
catch (System.Exception e)
{
e.printStackTrace ();
}
See below the Code for the Date Format Conversion
cabu.ui.validate.Formatter formatter = new OADateValidater (PaymentData, "dd-MMM-YY" "");
Thank you
Dilip
-
Need help getting A value in My App using xml/php http request
I know that maybe this isn't the place to ask questions about php, but I thought that people may have encountered a similar problem and I'm getting desperate basically my application's data is stored in a mysql database table, and what I have to do is to get the value of auto increment of this table in my application via an http request. I'm doing a php file that gets this value and displays this value in the xml format, but I'm terrible at creating php to do such things and just get the constant errors. Can someone take a look at this and help me to tweak it so it does what I want it please? The table in question is called links and the line/field/column in the table I'm after is called linkid. This is the next value of auto-increment this line printed in xml format, that's what I want. Here is the php so far:-
<?php header("Content-type: text/xml"); $host = ""; $user = ""; $pass = ""; $database = ""; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $tablename = "links"; $next_increment = 0; $qShowStatus = "SHOW TABLE STATUS LIKE '$tablename'"; $qShowStatusResult = mysql_query($qShowStatus) or die ( "Query failed: " . mysql_error() . "<br/>" . $qShowStatus ); $row = mysql_fetch_assoc($qShowStatusResult); $next_increment = $row['Auto_increment']; echo "next increment number: [$next_increment]"; ?>
Hello
step 1. the customer wants to add a new record. and sends a request for a new record
step 2. the server adds a new record in the database (now its Blanck) and returns its ID number
step 3. the customer has now has an appropriate identification number and use it to add a new object to the table
step 4. the customer with a registration ID and the new data for this "empty folder" is an update not an insert.
step 5. You now have the table and database synchronization.
David.
-
Need help with ics. SQL return null
Hi experts WCS.
I have this ics. SQL statement that returns an IList as null and nothing in the errStr in debugging print.
IList rsATypes is ics. SQL (, sqlATypes, listName, limit, bCache errStr);
The code is in one of my jsp. He ran very well in my local JSK (HyperSQL Db), but returns NULL in the case of Test (Oracle DB, if this is another).
I got the sql statement println during execution and run it directly in Oracle DB (same instance) it returns the expected result set.
The code snippet:
System.out.println("## ics.GetSSVar(\"pubid\") : " + ics.GetSSVar("pubid")); // Get Attribute Types String sqlATypes = "SELECT DISTINCT assetpublication.assettype " + "FROM assetpublication " + "LEFT JOIN approvedassets " + " ON assetpublication.assetid = approvedassets.assetid " + "WHERE pubid = '" + ics.GetSSVar("pubid") + "' " + "AND (tstate is null OR tstate <> 'A') " + "AND (voided is null OR voided <> 'T') " + "ORDER BY assettype; "; System.out.println("##0126 sqlATypes : " + sqlATypes); String from = "AssetPublication, ApprovedAssets"; // String listName = null; String listName = "ATypesList"; int limit = -1; // boolean bCache = true; boolean bCache = false; StringBuffer errStr = new StringBuffer(""); ics.ClearErrno(); IList rsATypes = ics.SQL(from, sqlATypes, listName, limit, bCache, errStr); System.out.println("## rsATypes : " + rsATypes); if (rsATypes == null) { System.out.println("## NO DATA in rsATypes! errStr : " + errStr.toString());
}
The journal:
## ics.GetSSVar("pubid") : 1374097570685 ## sqlATypes : SELECT DISTINCT assetpublication.assettype FROM assetpublication LEFT JOIN approvedassets ON assetpublication.assetid = approvedassets.assetid WHERE pubid = '1374097570685' AND (tstate is null OR tstate <> 'A') AND (voided is null OR voided <> 'T') ORDER BY assettype; ## rsATypes : null ## NO DATA in rsATypes! errStr :
I got enclosing try catch block, who did not take any exception.
The funny thing is, in the same piece of code, an ics. Casea used already worked (which I noticed outside because there was not enough for what I want to do):
StringBuffer errSB = new StringBuffer(""); ics.SetVar("assetid", id); IList approvedAsset = ics.SelectTo("ApprovedAssets", "state,voided,tstate,locked,reason,treason", "assetid", null, -1, null, true, errSB);
Any help/ideas from anyone would be really appreciated.
Thanks Guddu1223, I discovered why.
The SQL statement cannot end with a semicolon (see line 11 of my original above codes). Delete who had back all the records provided for in my resultset in the IList.
The reason why it works in my local, but not stable instance that I guess is my local JSK + HyperSQL, in WCS + Oracle DB instance trying...
-
Need help displaying the value of field in another!
I have a problem, I'm sure is simple but I can't understand it.
I would like to create a field that displays the value of a field point selecteed in drop down. For example, I created a drop down menu which has 3 times that I have assigned values to each:
Items in drop-down list
point: Unlimited time export assigned value: 4 000,00
point: 8-hours coverage export value assigned: 3,000.00
point: 5 hours Covrage export value assigned: 2,000.00
This drop-down list is named "CoverageTime".
I want to create a text called 'Price' field that will display the value of the selected 'CoverageTime' element drop-down list.
For example, if I chose "Unlimited" (which I have highlighted as 4,000.00) in the drop-down list, the 'Price' of text field should display the value of 'CoverageTime' of 4 000,00.
As you can see in my screenshot, I have selected ' Unlimted Time'. The value that I put to this element from the drop-down list is 4,000.00. But the price text field does not the value of the element "Unlimited time", selected in the drop-down list.
How to make this happen? (Sorry for the picture on the side)
I'm not sure what you mean about #1 (there is nowhere where to put the code in the tab Options), but it's okay because the second is on the right track. But to set the value of the field, assign anything you want event.value. So the correct code for the custom script to calculate the price of the text field:
The value of this field for the price of the value selected from the drop-down list
Event.Value = getField("CoverageTime").value;
-
Need help displaying Numberic values in app.alert
How can I display a decimal value placed two in an app.alert correctly?
App.Alert ("Invalid" - + this.getField("Sub-Total-2").value, 1);
In the above, alert Sub-Sub-Total-2 is set to 2 decimal places, within its text field properties. But if its value is 2.50, it appears in the form of 2.5 from within the alert. And othertimes, its value is always values such as 56.33333333, when it should display 56.40
Use util.printf)
-
I want to do
55830.01 = > 55840
55855.48 = > 55860
I try with the function round, but did not get the result... Please help meWell, you could do it this way
ceil (col/10) * 10
and with a complete example
SQL> with test as 2 (select 55830.01 col from dual union all 3 select 55855.48 from dual 4 ) 5 select col 6 , ceil (col/10) * 10 7 from test 8 / COL CEIL(COL/10)*10 ---------- --------------- 55830.01 55840 55855.48 55860
-
Need help with a Committee and return...
So, here's my dilemma... have a production system that I took a picture of before I did an upgrade (save on 27/04/12). the upgrade looked like it worked but actually broke some other components. so I took a snapshot (after saving) and said to go to backup 27/04/12 (in case I wanted to retry the upgrade). so here I am with my current state in the middle of the parent company and a snapshot which I want to remove. I remove my instantaneous current (27/04/12 backup) and then try to come back to get rid of the snapshot "after backup"? and this might be a stupid question... but why it looks like the image that the snapshot running is the snapshot "after backup" (green arroqw) when the you are indication here that I do run the backup snapshot from 27/04/12?
It depends on where you are currently in the chain. Since you are within the string before "after backup", it will reject just that. Since you are after the snapshot of the 27/04/12, commit only.
If you are worried about deleting a snapshot change your current state of the virtual machine, it won't happen. Whatever it is, where you're started inside the virtual machine when you delete will not change.
-
new and need help with the value $ in a sale
I have just come across this product and h
Ave fall in love with. question: how to format
from field pays $ 0.00 in
the number field instead of only 18
all free used is appreciated
Define the display pattern for the numeric field to num {($z9.99)} to display as $18.00 18...
Thank you
Srini
-
Need help with the query using the AVG function
First post here.
I am a student taking a SQL class and I can't find a query.
I think I'm close to get it, but I can not quite all the way there.
Three tables are involved in this problem. Here is a list of the tables and the areas concerned:
Problem:orders table: order# shipstate orderitems table: order# isbn quantity (How many copies of book purchased on that order) books table: isbn retail (retail price of book)
I want to get an average of "total amount" by shipstate.
For example, in these tables, there are 8 records of the State of Florida.
However, there are only 5 unique order # for this State.
The amount of detail * quantity for these 8 disks (or 5 orders) is $345,10
Now to get my average $345,10 should be divided by 5. (number of unique commands)
In the following query it divides this $345,10 8. (number of records)
How to make this request to divide by the number of unique order # rather than the number of records?
According to me, once I get this part down, I can understand the rest of the problem.SELECT shipstate, AVG(quantity * retail) FROM orders JOIN orderitems USING (order#) JOIN books USING (isbn) GROUP BY shipstate HAVING SUM(quantity * retail) =ANY (SELECT SUM(quantity * retail) FROM books JOIN orderitems USING (isbn) JOIN orders USING (order#) GROUP BY shipstate)
The end result, I need, is to find all the individual commands that have a "total amount due" that is greater than the 'average amount due' for this state of clients.
Any help, suggestions or comments welcome.
MattYour average take into account the shipstate (8 disks), you can do that for the expected results.
With some examples of input data it would be easier, but here a try:SELECT shipstate, sum(quantity * retail)/count(distinct order#) FROM orders JOIN orderitems USING (order#) JOIN books USING (isbn) GROUP BY shipstate;
Nicolas.
delete the alias
Edited by: N. Gasparotto on October 3, 2008 19:28 -
Need help to change the setting of the function key in Windows 8, help?
Hey, I bought a HP laptop yesterday (which I am very satisfied) and decided to play Guild Wars 2 and all of my favorite PC games. In the game, I discovered that all of the F buttons work without pressing FN, which is annoying. So although I am tyring to combat various things I'll always turn down the brightness and turn off the wireless so if I could know how to swap it around, so when I press FN I can turn down brightness etc that would mean I could now use the F buttons normally any help would be nice thank YOU!
Hello
You should be able to change this setting in your Bios menu - see the document at the following link.
http://support.HP.com/us-en/document/c02035108
Kind regards
DP - K
-
need help to recover my account
my account as pirate summer since July, I tried to recover my account but no, I've tried everything then what else can I need help... like to return my account my account is * address email is removed from the privacy * and e-mail, you can reach me at is now * address email is removed from the privacy... *
Hello
The question you posted would be better suited to Windows Live Solution Center. I suggest you to send your application in the Windows Live Solution Center for better support.
-
Help with the UpdateView() method inside my function
Hi all!
Right, I started my journey to the bottom of the more 'Advanced' way of using Powercli scripting languages and in the process have resulted in a few questions that I try to answer. I have created an advanced function of earlier and was very "impressed" (sorry only word I could think ) with it as it has been very useful in my work on the day the day. This lead me on the creation of the more advanced functions and placing them in a "module" folder\file. However, even if the majority of them is reporting back exactly what I wanted. THE MAIN PROBLEM IS THE PERFORMANCE. We have a very large domain (3000 VMs) and the VM back news taking so long.
So after having posted on gettting here and thankfully not only my answered by LucD but LucD send me pointers as to where I can go to the question. I read the links he sent me and same have bought book of Steve Jins. My knowledge is improvin, but seem to be stuck here and need help.
I have attached my function below and would like someone to talk me through the following:
1. I understand the cmdlet Get-view works now and especially in conjunction with my function below. I tested it and it works great and IS faster than just using the approach of the cmdlet. I understand that the .NET view is simply a larger range of objects that can be much faster retrieve? He has worked and is faster when I tested it. I am so satisfied with the aspect of get-view of things.
2. now leading me on the method of UpdateViewData() - how can I (or can I?) incorporate into my function. I added in, but I don't know if I used it properly, or even if it's supposed to be used like this if someone can help that will be greatly appreciated.
Any help would be as always be appreciated
Thanks in advance
Munster
Function Get-VirtualmachinesInfo {}
< #.
# >
[CmdletBinding()]
(PARAM
[Parameter (mandatory = $true,)]
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Please enter the VM name")]
[ValidateNotNullOrEmpty()]
[String []] $VMName
)
BEGIN {$OutputObj = @ () # output initialization object array
}
{IN PROCESS
Try {}
{Foreach ($VM to $VMName)
If ($VM. GetType(). Name - eq 'string') {}
Try {}
$VM = get - VM $VM - ErrorAction Stop
}
{} Catch [Exception]
Write-Warning "$VM is NOT a virtual machine.
continue
}
}
} ElseIf ($VM - isnot [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl])
Write-Warning "you not pass a string or a VM object.
continue
}
"$VMView get-View - ViewType Virtualmachine-filter = @{'name' = $vm.name}.
-Name of the property, config, summary
$VMView | %{$_. UpdateViewData ("VM. "Name", "VM.config", "VM. Summary")}
$Props = [ordered]@{'Name'=$VMView.name;
'Version' = $VMView.config.version;
'UuID' = $VMView.config.Uuid;
'CPU_Num' = $VMView.config.hardware.NumCPU;
'CorSkt_Num' = $VMView.config.hardware.NumCoresPerSocket;
"Nics_Num" = $VMView.summary.config.NumEthernetCards;
"VHDs_Num" = $VMView.summary.config.NumVirtualDisks;
}
$Obj PSObject = new-Object-property $Props
$OutputObj += $Obj
}
}
{} Catch [Exception]
THROW "could not get the VM details, please confirm that the virtual machine exists."
}
}
{END}
Write-Output $OutputObj # exit EXIT pipeline objects
}
}
Fix.
-
Need help to select the value of the affected line
Hello! I need help to write a statement Select returns a value of the respective line in a table. I have a table that contains an id and a name of entity and a table of addresses with the lines of address, city, province/state, country, etc, which is linked through the identifier. There may be several lines in this table for any entity id given etc. which are distinguished by a type of address for example Mailing, billing, payment, shipping,. I'm writing a view that returns the name of the entity, the city and the State. I want to use the address of delivery, if it exists, otherwise, I want the broadcast address. One of these types of addresses will still exist, and it is possible that both will exist. I'm just back to SQL after a prolonged absence and am not familiar with some of the new features. I'm also new to the Oracle community. We are on Oracle 11.2. Any help would be greatly appreciated. Thank you!!
P.S. I posted this question a couple of weeks and got some responses. But I can't find the post. I thought I posted it here, but who knows! As I said, I'm new on this.
Hello
Here is an example of how to join another table to results of Top - N all:
WITH got_r_num AS
(
SELECT deptno, job, ename, sal, hiredate
Rank () OVER (PARTITION BY deptno
CONTROL OF CASE work
WHEN PRESIDENT", THEN"A ".
WHEN 'MANAGER' THEN 'B '.
END
) AS r_num
FROM scott.emp
WHERE job IN ('MANAGER', 'PRÉSIDENT')
)
SELECT d.deptno, d.dname
r.ename, r.job, r.sal, r.hiredate
Got_r_num r
JOIN scott.dept d.deptno d = r.deptno
WHERE r.r_num = 1
ORDER BY d.deptno
;
-
I want to return a plug-in, I accidentally deleted.i to play online snooker.can someone at - it need help please?
Hello
1. What plugin you are talking about?
2. on which site Web you are trying to play the game of billiards online?
3. what web browser do you use?
4. how exactly did you uninstall the plug?
Plug-ins are provided by third-party providers, you can try to load the game of billiards and verification that branch is needed.
Please come back with more information on the issue so that we can help you better.
You can also visit the link of the article of Microsoft that will guide you on how to ask questions below.
Suggestions for a question on the help forums
Maybe you are looking for
-
Customers known address are sent to spam
Some clients are not allowed through, even if they are in my address list.
-
Unable to synchronize the folder "sent" on the new installation of IMAP (resolved)
Installed Thunderbird, configure an IMAP account. Only Inbox and trash have been posted in the narrow pane on the left. I searched the community and assistance, I have not found a solution. I solved the problem by sending a message to another one of
-
Registration and getting started with the INK HP INSTANT
Registration and getting started with ink HP Instant Note: your printer must be connected to the Internet via a wireless connection. How does that you will always have ink HP? Your printer uses Internet to let us know when to send more ink. Here's ho
-
Wake on LAN in the BIOS not available
3847 Inspiron desktop computer. I want WOL to work. It is said in the BIOS disabled. However, it is also grayed out and I can't move allow. Link light is NOT on when power off. Other card network through the operating system settings are enabled, but
-
Cannot figure out how to turn on bookmarks.
Cannot figure out how to turn on bookmarks. Acrobat DC.