SQL - Find Records continues
I'm looking for some SQL tips on finding continuous records in a table. The table in question looks like this:ID LITH DEPTH
1-1 150 SAND
1-1 COAL 200
1-1 SAND 250
1-1 COAL 300
2-2 SAND 75
2-2 COAL 100
2-2 COAL 150
2-2 COAL 200
2-2 COAL 250
SAND 2-2 300
2-2 COAL 400
2-2 COAL 450
I am trying to locate the records marked in bold above and count the number of times they occur. In the example above, I would like to come back:
ID of account
1-1 null
2-2 4
2----2 2
I know it's a problem that can be solved outside the database with excel for example. However, I'd appreciate it really all the tips on how to solve this problem with SQL.
The following lists all the consecutive depth (50 step):
SQL> with tab as (
2 select '1-1' id, 'SAND' lith, 150 depth from dual union
3 select '1-1' id, 'COAL' lith, 200 from dual union
4 select '1-1' id, 'SAND' lith, 250 from dual union
5 select '1-1' id, 'COAL' lith, 300 from dual union
6 select '2-2' id, 'SAND' lith, 75 from dual union
7 select '2-2' id, 'COAL' lith, 100 from dual union
8 select '2-2' id, 'COAL' lith, 150 from dual union
9 select '2-2' id, 'COAL' lith, 200 from dual union
10 select '2-2' id, 'COAL' lith, 250 from dual union
11 select '2-2' id, 'SAND' lith, 300 from dual union
12 select '2-2' id, 'COAL' lith, 400 from dual union
13 select '2-2' id, 'COAL' lith, 450 from dual
14 )
15 select id, lith, depth, max(level)
16 from tab
17 where connect_by_isleaf=1
18 connect by prior id = id and prior lith = lith and prior depth=depth+50
19 group by id, lith, depth
20 order by id, depth;
ID LITH DEPTH MAX(LEVEL)
--- ---- ---------- ----------
1-1 SAND 150 1
1-1 COAL 200 1
1-1 SAND 250 1
1-1 COAL 300 1
2-2 SAND 75 1
2-2 COAL 100 4
2-2 SAND 300 1
2-2 COAL 400 2
8 rows selected.
And what follows hiding records at least two of the following records:
SQL> with tab as (
2 select '1-1' id, 'SAND' lith, 150 depth from dual union
3 select '1-1' id, 'COAL' lith, 200 from dual union
4 select '1-1' id, 'SAND' lith, 250 from dual union
5 select '1-1' id, 'COAL' lith, 300 from dual union
6 select '2-2' id, 'SAND' lith, 75 from dual union
7 select '2-2' id, 'COAL' lith, 100 from dual union
8 select '2-2' id, 'COAL' lith, 150 from dual union
9 select '2-2' id, 'COAL' lith, 200 from dual union
10 select '2-2' id, 'COAL' lith, 250 from dual union
11 select '2-2' id, 'SAND' lith, 300 from dual union
12 select '2-2' id, 'COAL' lith, 400 from dual union
13 select '2-2' id, 'COAL' lith, 450 from dual
14 )
15 select id, count from (
16 select id, lith, depth, max(level) count
17 from tab
18 where connect_by_isleaf=1
19 connect by prior id = id and prior lith = lith and prior depth=depth+50
20 group by id, lith, depth
21 order by id, depth
22 )
23 where count>1;
ID COUNT
--- ----------
2-2 4
2-2 2
Do you really need the folder with ID = 1-1' and count = null?
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]
Tags: Database
Similar Questions
-
Query to find records with more than 2 decimal places.
Output:-I have written the below query to find records with more than 2 decimal places, but it is returning records with decimal places 1 & 2. The datatype of the AMT column is NUMBER (without any precision). SELECT amt FROM amount_table WHERE substr(amt, instr(amt, '.')) LIKE '.%' AND length(substr(amt, instr(amt, '.') + 1)) > 2
AMT
* 41591.1*
* 275684.82*
* 64491.59*
* 3320.01*
* 6273.68*
* 27814.18*
* 30326.79*
131.8413635
162.5352898
208.5203816
8863.314632
22551.27856
74.716992
890.0158441
2622.299682
831.6683841
* 1743.14*
2328.195877
3132.453438
5159.827334
3.236234727
37.784
Thanks
Hello
user1585440 wrote:
when i inserted fee_amt as 41591.0999999999 it is displayed as 41591.1 in the output i.e, insert into amount_table (line_number,fee_amt) values (100,41591.0999999999); select fee_amt from amount_table where line_number = 100. this query shows the output as below fee_amt 41591.1 The fee_amt column has number as datatype (without precision) Why it is automatically shown rounded off as 41591.1?
Published by: user1585440 on December 28, 2010 04:50
You use SQL * more your front end?
SQL * Plus has a fixed width to display all columns. The default for numbers is 10 characters. If necessary, SQL * Plus will be round a number or the use of scientific notation, to represent the number of the expected number of characters.
You can use the SQL * more "SET NUMLARGEUR" to change the default view for all the numbers of orders, or "COLUMN" to set a sepcific format in an individual column.
If you explicitly convert your channel numbers in a query, SQL * Plus adjusts the column width to whatever is needed. For exampleSELECT TO_CHAR (fee_amt, 'TM') AS fee_amt_d
"TM" is the default format; You can call TO_CHAR with a single argument, if you prefer.
-
Find records overlapping start and end dates
Hi all
I have a table with begin and end date columns. I need to find the records that overlap with a few values in corresponding column.
Table: MG_AUTH_AGNT
-----
ID
MGATH_clnt
MGATH_beg_DT
MGATH_END_DT
MGATH_SERV_GRP
MGATH_STAT
MGATH_TYP
MGATH_NHIC_ERR_CD
-----
I need to find records containing dates that overlap.
Examples of data
-----
If the customer has two records with the same MGATH_SERV_GRP, MGATH_STAT, MGATH_TYP and start and end dates of the first disc are 01/JAN/2009 AND 01 / JAN / 2009.
start and end dates of second record are 15/JAN/2009 and 15/FEB/2009.
Here are the dates overlap. with my select query, I should get these two recordings.
I am using the following query. But it is too slow. Could you please suggest a better sql?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Select MG_AUTH_AGNT m, MGATH_clnt, MGATH_beg_DT, MGATH_END_DT, MGATH_NHIC_ERR_CD, id where m.MGATH_SERV_GRP = '1' and m.MGATH_STAT = 'A' and MGATH_clnt = (select distinct MGATH_clnt of MG_AUTH_AGNT d where d.MGATH_SERV_GRP = m.MGATH_SERV_GRP and d.MGATH_TYP = m.MGATH_TYP and m.MGATH_CLNT = d.MGATH_CLNT and d.MGATH_STAT = m.MGATH_STAT and m.idd.id ((trunc (m.MGATH_beg_DT) & gt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_beg_DT) & lt;=trunc(d.MGATH_END_DT)) or (trunc (m.MGATH_END_DT) & gt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_END_DT) & lt; = trunc (d.MGATH_END_DT)) or (trunc (m.MGATH_beg_DT) & lt; = trunc (d.MGATH_beg_DT) and trunc (m.MGATH_END_DT) & gt; = trunc (d.MGATH_END_DT))) MGATH_clnt order MGATH_beg_DT
Published by: user10727414 on March 17, 2009 01:36user10727414 wrote:
My data is correctMGSRV_CLNT = MGSRV_BEG_DT = MGSRV_END_DT
501184242 = 28-AUG-07 = 31-DEC-9999
501184242 = 28-AUG-07 = 31-DEC-9999
501184242 = 20-DEC-07 = 31-DEC-9999
501184242 = 20-DEC-07 = 31-DEC-9999And we had to guess that a year of "99" was in fact "9999" were we? Hang on I'll go and dust off my crystal ball.
Well, now we know the correct dates (?), we'll put that in the original request...
SQL> ed Wrote file afiedt.buf 1 with mypeople as 2 (select 501184242 as id, to_date('28-AUG-2007','DD-MON-YYYY') as stdt, to_date('31-DEC-9999','DD-MON-YYYY') as endt from dual union all 3 select 501184242, to_date('28-AUG-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 4 select 501184242, to_date('20-DEC-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 5 select 501184242, to_date('20-DEC-2007','DD-MON-YYYY'), to_date('31-DEC-9999','DD-MON-YYYY') from dual union all 6 select 2, to_date('19/01/2009','DD/MM/YYYY'), to_date('24/01/2009','DD/MM/YYYY') from dual) 7 -- END OF TEST DATA 8 select id, stdt, endt 9 ,case when lead(stdt) over (partition by id order by stdt,endt) <= endt 10 or lag(endt) over (partition by id order by stdt,endt) >= stdt then 'Overlap' 11 else 'Ok' 12 end as status 13 from mypeople 14* order by id, stdt, endt SQL> / ID STDT ENDT STATUS ---------- --------- --------- ------- 2 19-JAN-09 24-JAN-09 Ok 501184242 28-AUG-07 31-DEC-99 Overlap 501184242 28-AUG-07 31-DEC-99 Overlap 501184242 20-DEC-07 31-DEC-99 Overlap 501184242 20-DEC-07 31-DEC-99 Overlap SQL>
Looks like it works for me.
If it does not work for you then maybe had better give us a statement of create table and insert to your data in the example statements then we can see what you're trying to do.
-
retrieve and record continuous images in labview
Hello
I use the NI 1744 smart camera to capture and record continuous images of a moving object. My smart camera is detected in MAX and made the seizure of an image. But when I use the attached file of VI in labview, the smart camera is not detected, only the webcam is detected and a video can be generated using the webcam. Please help me detect the NI 1744 smart camera. I will be grateful.
Hello
Your smartcam is not directly accessible from your PC because it is a remote device.
Create a project in real time to access your camera.
Have a look here: http://forums.ni.com/t5/Machine-Vision/Error-1074397145/m-p/535230/page/2?view=by_date_ascending
Concerning
-
Finding records with timestamps
Hello
I want find records in a table where a certain column not only contains dates, but also contains a timestamp. For example, I would like to find records in which the value of the column is like that.
23/08/2010-20:02:29
The data type of the column you are looking for is the DATE.
The column also contains values of date without timestamps. Thank you!Maybe
where date_column != trunc(date_column)
Concerning
Etbin
-
SQL - find the minimum value for each separate record...
Hi all
I have a table like this in SQL Server
Date of sale of product
A date
A date
A date
B date of
B date of
C date
C date
C date
I would like to write a query to find the minimum date (i.e. the date
the first sale) for each product
Thus, the expected results would be
Date of sale of product
A date min
B date of min
C date of min
How can I do this using SQL Server?
any help is greatly appreciated!
Thank you!
Product SELECTION, MIN (sale_date)
From your_table
GROUP BY productEtienne
-
pl/sql dynamic record statement
Hi all
I am very curious to find a way to declare a dynamic record type in the Declaration of a PL/SQL block section. Forgive me if I do not use the right jargon. I am a newbie to pl/sql.
I work with the HR schema that comes integrated with SQL Developer. My procedure resembles
---------
create or replace
PROCEDURE PROC3 (v1 in v2 in VARCHAR2, VARCHAR2) IS - v1 = employees; v2 = tmp_emp_1
v_str VARCHAR2 (100);
MSG VARCHAR2 (50);
MSG2 VARCHAR2 (50);
msg3 VARCHAR2 (50);
var_rows VARCHAR2 (50);
var1_rows VARCHAR2 (50);
var2_rows varchar (50);
table_not_found EXCEPTION;
code_text VARCHAR2 (50);
v_str1 VARCHAR2 (100);
v_str2 VARCHAR2 (50);
v_str3 VARCHAR2 (100);
v_str4 VARCHAR2 (100);
var_ins VARCHAR2 (100);
var_ins2 VARCHAR2 (100);
v_cur VARCHAR2 (100);
TYPE emp_rec_var IS table of employees % rowtype;
-employee table emp_rec_var IS % ROWTYPE;
SheikYerbouti emp_rec_var; -SheikYerbouti is a table
-v_cur: = ' cursor emp_insert is Select * from '. v1;
Type emp_insert_ref is ref cursor;
emp_insert emp_insert_ref; -emp_insert is a cursor
BEGIN
-Drop the tmp_emp_1 table
v_str: = 'DROP table ' | v2;
run immediately (v_str);
var_rows: = SQL % ROWCOUNT;
dbms_output.put_line ('Table tmp_emp_1 with' | var_rows |) "lines has been abandoned");
-Tmp_emp_1 table creation
v_str1: = 'CREATE table ' | v2 | ' in select * from '. v1 | "where 1 = 0';
run immediately (v_str1);
-Inserts in tmp_emp_1 via an Insert bulk
var_ins: = 'Insert into ' | v2 | ' (select * from ' | v1 | ")'; » ;
var1_rows: = SQL % ROWCOUNT;
dbms_output.put_line ('Total of ' | var1_rows |) "the lines have been inserted in tmp_emp_1 through bulk insert");
-A fall tmp_emp_1
v_str2: = 'Drop table ' | v2;
run immediately (v_str2);
-Creation of tmp_emp_1
v_str3: = 'Create table ' | v2 | "in select * from employees where 1 = 0';
run immediately (v_str3);
-Insert in tmp_emo_1 via the emp_insert slider
Open for Emp_insert
' Select * from '. v1;
Get the emp_insert COLLECT IN BULK SheikYerbouti.
for n in emp_rec.first... emp_rec loop. Last
v_str4: = "insert" | v2 | ' (employe_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, manager_id, department_id)
values (SheikYerbouti (n) .employee_id, SheikYerbouti (n) .first_name, (n) .last_name, .email SheikYerbouti SheikYerbouti (n), SheikYerbouti (n) .phone_number, SheikYerbouti (n) .hire_date, SheikYerbouti (n) .job_id, (n) SheikYerbouti .salary SheikYerbouti (n) .commission_pct, SheikYerbouti (n) .manager_id, emp_rec (n) .department_id)';
run immediately (v_str4);
var2_rows: = SQL % ROWCOUNT;
dbms_output.put_line ('Total of ' | var2_rows |) "lines have been inserted in tmp_emp_1 through slider emp_insert");
end loop;
Close Emp_insert;
EXCEPTIONS - Management error
WHILE OTHERS THEN
dbms_output.put_line (' unexpected error!) You need to be better at programming dumb-ass! ") ;
NULL;
END PROC3;
------
For the line in bold above ' + TYPE emp_rec_var IS table employees % rowtype + ', I want to replace it with "employees" to the variable "v1" (declared in the procedure) so that the record statement of 'TYPE' becomes dynamic. Any suggestions are welcome.
Thank youYou cannot declare a record type dynamically.
You can, if you were really desperate, use dynamic PL/SQL construction instead of simply using dynamic SQL. It is very rare, however, that dynamic SQL is actually a good idea and it is extremely rare that the dynamic PL/SQL use is a good idea. You call yourself a newbie makes me strongly suspect that you really want to focus on learning to do things normally don't not focusing on features that are rarely used correctly and frequently abused.
Justin
-
Find records in the date range
Hello
I have the following data
What is the best way to find all records in April 1, 2012 and April 30, 2012?with t as ( select 1234 prod_id, to_date('01-Jan-2008', 'dd-MON-yyyy') start_date, to_date('01-May-2012', 'dd-MON-yyyy') end_date from dual union select 4567 prod_id, to_date('01-Aug-2007', 'dd-MON-yyyy') start_date, to_date('01-Apr-2012', 'dd-MON-yyyy') end_date from dual union select 8910 prod_id, to_date('01-Jul-2006', 'dd-MON-yyyy') start_date, to_date('01-Mar-2012', 'dd-MON-yyyy') end_date from dual ) SELECT * FROM t
ConcerningAssuming that you are looking for cumulation ranges
SELECT * FROM t WHERE start_date BETWEEN date '2012-04-01' and date '2012-04-30' OR end_date BETWEEN date '2012-04-01' and date '2012-04-30' OR ( start_date < date '2012-04-01' AND end_date > date '2012-04-30' )
who produces the two lines expected
SQL> with t as ( 2 select 1234 prod_id, to_date('01-Jan-2008', 'dd-MON-yyyy') start_date, to_date('01-May-2012', 'dd-MON-yyyy') end_date 3 from dual union 4 select 4567 prod_id, to_date('01-Aug-2007', 'dd-MON-yyyy') start_date, to_date('01-Apr-2012', 'dd-MON-yyyy') end_date 5 from dual union 6 select 8910 prod_id, to_date('01-Jul-2006', 'dd-MON-yyyy') start_date, to_date('01-Mar-2012', 'dd-MON-yyyy') end_date 7 from dual 8 ) 9 SELECT * 10 FROM t 11 WHERE start_date BETWEEN date '2012-04-01' and date '2012-04-30' 12 OR end_date BETWEEN date '2012-04-01' and date '2012-04-30' 13 OR ( start_date < date '2012-04-01' 14 AND end_date > date '2012-04-30' ); PROD_ID START_DAT END_DATE ---------- --------- --------- 1234 01-JAN-08 01-MAY-12 4567 01-AUG-07 01-APR-12
Justin
-
Form does not display the 'new' SQL database records
I have a PDF form that retrieves data from a SQL Server. The fields of
the PDF are filled from the database after you have selected a specific
record in a menu drop down and clicking a button called 'bridge '.
The problem is that the drop-down list does not display new records that
have been recently added to the database. I have to open the form
in the designer, and then save it, (* note - I change anything at this point.)
Then, when the form is opened upward in Adobe drop-down list show all
the documents, including the new ones. I even put a manual on refresh
form to try to solve the computer problem has not helped. Seriously left speechless.Any help is greatly appreciated.
Here is my code for the menu drop down.++++++++++++++++++++++++++++
topmostSubform.Page1.JobSelect::initialize - (JavaScript, client)
var sDataConnectionName = "BBCC" example - var sDataConnectionName
= 'Test ';
var sColHiddenValue = "ContractAdmin_Key"; example - var
sColHiddenValue = "Dept_ID";
var sColDisplayText = "JobDescription". example - var
sColDisplayText = "Dept_ID".Search for sourceSet node that match the name of DataConnection
var nIndex = 0;
While (xfa.sourceSet.nodes.item (nIndex) .name! = sDataConnectionName)
{
nIndex ++;}oDB var = xfa.sourceSet.nodes.item (nIndex);
oDB.open ();
oDB.first ();Search with the command 'class name' node
var nDBIndex = 0;
While (oDB.nodes.item (nDBIndex) .className! = 'command')
{
nDBIndex ++;}Save the original settings before you assign it, BOF and EOF to stay
var sBOFBackup =
oDB.nodes.item (nDBIndex).query.recordSet.getAttribute ("bofAction");
var sEOFBackup =
oDB.nodes.item (nDBIndex).query.recordSet.getAttribute ("eofAction");oDB.nodes.item (nDBIndex).query.recordSet.setAttribute ("stayBOF",
"bofAction");
oDB.nodes.item (nDBIndex).query.recordSet.setAttribute ("stayEOF",
"eofAction");Clear list
this.clearItems ();Find the record with the corresponding data connection name
nIndex = 0;
While (xfa.record.nodes.item (nIndex) .name! = sDataConnectionName)
{
nIndex ++;}var oRecord = xfa.record.nodes.item (nIndex);Find the value
var oValueNode = null;
var oTextNode = null;
for (var nColIndex = 0; nColIndex < oRecord.nodes.length; nColIndex ++)
{If (oRecord.nodes.item (nColIndex) .name is sColHiddenValue)
{oValueNode = oRecord.nodes.item (nColIndex) ;} on the other
If (oRecord.nodes.item (nColIndex) .name == sColDisplayText) {oTextNode
= oRecord.nodes.item (nColIndex); } }While (!) ODB. IsEOF())
{
this.addItem (oTextNode.value, oValueNode.value);
oDB.next ();}Restore the original settings
oDB.nodes.item (nDBIndex).query.recordSet.setAttribute (sBOFBackup,
"bofAction");
oDB.nodes.item (nDBIndex).query.recordSet.setAttribute (sEOFBackup,
"eofAction");Close connection
oDB.close ();++++++++++++++++++++++
Here is the code for the button refresh
+++++++++++++++++++++
topmostSubform.Page1.Button27::click - (JavaScript, client)
sourceSet.BBCC.requery ();+++++++++++++++++++++
The other thing that could happen is a problem of refreshment in the DropDownList control. Try to add the command xfa.layout.relayout () after the database connection has been closed.
Paul
-
How to find records given a child parent key
I have a main table that is parent for several children tables. I want to display a button to delete a record in the primary table. I would have preferred to see the this key conditionally so when a master record's child records, I don't show button Delete and no error is raised.
Of course I could scan each child table to find the child records, but I think that must be a generic method
How can I tell if a given parent key has child records?
Thanks in advance
Oscar
PS: I use 10 gr 2
Published by: user10712087 on 01/13/2009 14:31Oscar
There is no magic/generic way to verify that a main line has no associated detail line. As says Pavan, you must decide which detail the tables to check and them using SQL as usual. (In fact, there is a quick way - you remove the line if there is no child rows with foreign keys which is not cascade, the delete will fail; but of course you can't use this in case the deletion succeeds and the user never wants to push the button).
An addition to the Pavan response: DO NOT under any circumstances to count all records in the table of every detail. Everything you want to know is, is it at least 1 record retail at least 1 tables. No need to count the lines 100 or 1000...
You can do it like this in your PL/SQL
FUNCTION check_children(p_master_id IN INTEGER) RETURN BOOLEAN IS CURSOR c_child1 IS select 1 from child_table_1 where master_id = check_children.p_master_id; CURSOR c_child2 IS select 1 from child_table_2 where master_id = check_children.p_master_id; -- etc for all child tables l_rec_present integer := null; BEGIN OPEN c_child_1; FETCH c_child_1 INTO l_rec_present; CLOSE c_child_1; IF l_rec_present i= 1 THEN -- there is a child in child_table_1 RETURN TRUE; END IF; OPEN c_child_2; FETCH c_child_2 INTO l_rec_present; CLOSE c_child_2; IF l_rec_present i= 1 THEN RETURN TRUE; END IF; -- etc for each child; finally, if no child found: RETURN FALSE; END;
This made sure that (1) you stop once you find any child, and (2) you get all NO_DATA_FOUND and TOO_MANY_ROWS exceptions thrown.
HTH
Nigel cordially
-
Re: Where to find the Continua Bluetooth Manager?
I'm looking for the Bluetooth Manager continued for Windows, manufactured by Toshiba, but I have no idea where to find it. This (http://continuaalliance.org/certified-products/continua-bluetooth-manager-for-windows-manufactured-by-toshiba.html) is the only thing that I find, but where to download?
Looking for Toshiba SDKS for developers of BT?
Check it out here:
http://APS2.toshiba-tro.de/KB0/HTD9602MK0000R02.htmFound the interesting thread on a similar question:
http://forums.computers.Toshiba-Europe.com/forums/thread.jspa?threadID=57899 -
Equium A100-147: record now and Roxio can't find Recorder
Equium A100-147 with Sonic, 'Save now' 7 worm, using gives 'NO recorder' and can not find the drive. If no records. I checked the box 'Save' in the properties for the drive but no joy. Also I tried Roxio software but it was also unable to find the drive.
All of the suggestions.
See you soon.Please check in Device Manager if the cd/dvd drive is correctly recognized.
Additional if you can find the drive in the Device Manager, you could try to remove it and restart the laptop.
After restarting the laptop should recognize the device again.
Then you should check the functionality of the drive.I studied a bit on the site of Microsoft for similar problems and found a few interesting sites:
http://support.Microsoft.com/kb/320553
http://support.Microsoft.com/kb/314060/In my opinion, some registry entries are corrupted.
-
AnalogWafeform Timing.StartTime is the same for the different records continues mode!
We read samples from the Commission NI 6132 DAQmx interface in continuous mode, i.e.
inputTask.Timing.ConfigureSampleClock (string. Empty, 1000000, SampleClockActiveEdge.Falling, SampleQuantityMode.ContinuousSamples, 1000);
We read the analog waveform records successfully in call back, and we look at samples - they are correct.
We need to know the moment when trigger onset occurred for each acquisition.The data is read to the variable
AnalogWaveformawf =...; and we do the following
If (AWF. IsPrecisionTimingInitialized)
{
InitialXTimeSeconds = awf. PrecisionTiming.StartTime.WholeSeconds;
InitialXTimeFraction = awf. PrecisionTiming.StartTime.FractionalSeconds;
}The problem: InitialXTimeSeconds and InitialXTimeFraction are the same for all records and equal at the beginning of the task, i.e. time of the acquisition of the first record. What's wrong?
Hey, I noticed that you posted this question in another forum here. Continue to work on this in this forum.
-
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
-
Need help with Oracle SQL merge records according to date and term dates
Hi all
I need help to find this little challenge.
I have groups and flags and effective dashboards and dates of term against these indicators according to the following example:
GroupName Flag_A Flag_B Eff_date Term_date Group_A THERE THERE 20110101 99991231 Group_A N N 20100101 20101231 Group_A N N 20090101 20091231 Group_A N N 20060101 20081231 Group_A N THERE 20040101 20051231 Group_A THERE THERE 20030101 20031231 Group_B N THERE 20040101 99991231 Group_B N THERE 20030101 20031231 As you can see, group_A had the same combination of (N, N) flag for three successive periods. I want to merge all the time periods with the same indicators in one. Where entry into force will be the most early (underlined) time period and end date will be later (underlined)
So the final result should look like this:
GroupName Flag_A Flag_B Eff_date Term_date Group_A THERE THERE 20110101 99991231 Group_A N N 20060101 20101231 Group_A N THERE 20040101 20051231 Group_A THERE THERE 20030101 20031231 Group_B N THERE 20030101 99991231 Thanks for your help
Here's the DDL script
drop table TMP_group_test;
create table TMP_group_test (groupname varchar2 (8))
, flag_a varchar2 (1)
, flag_b varchar2 (1)
, eff_date varchar2 (8)
, term_date varchar2 (8)
);
insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20110101 ', ' 99991231');
insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20100101 ', ' 20101231');
insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20090101 ', ' 20091231');
insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20060101 ', ' 20081231');
insert into TMP_group_test values ('Group_A', 'n', 'Y', ' 20040101 ', ' 20051231');
insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20030101 ', ' 20031231');
insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20040101 ', ' 99991231');
insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20030101 ', ' 20031231');
commit;
Post edited by: user13040446
It is the closest, I went to the solution
I create two rows;
Rnk1: partition by group name, order of eff_date / / desc: this grade will sort the records of the most recent and handed to zero for each group\
Rnk2: (dense) partition by group name, flag_A, flagb: this grade for each combination of group\flag gives a number so that they are classified as "families".
Then I use the function analytic min
Min (eff_date) more (partition of GroupName, rnk2): the idea is that, for each Member of the same family, the new date is the min of the family (and the max for the date of the term), at the end I just need separate so that the duplicates are gone
Now the problem. As you can see from the query below, records of 1 and 6 (as identified by rownum) are identified in the same family, because they have the same combination of flag, but they are not successive, so everyone must keep its own date of entry into force.
If only I can make the distinction between these two that would solve my problem
Query:
Select rowNum,GroupName, flag_a, flag_b, eff_date, term_date, rnk1, rnk2
, min (eff_date) more than (partition by GroupName rnk2( ) min_eff
Of
(
Select rowNum,
GroupName , flag_a , flag_b , eff_date , term_date
rank() more than (partition by GroupName stopped by eff_date desc) rnk1
DENSE_RANK() more than (partition by GroupName order by flag_A flag_B ( ) rnk2
de dsreports . tmp_group_test
) order by rowNum
Hello
user13040446 wrote:
Hi KSI.
Thanks for your comments, you were able to distinguish between these lines highlight, but lost lines 2,3,4 which are supposed to have the same date min = 20060101.
Please see the table wanted to see the final result I want to reach
Thanks again
This first answer is basically correct, but in the main query, you want to use the function MIN, not the analytical function aggregation and GROUP BY columns with common values, like this:
WITH got_output_group AS
(
SELECT GroupName, flag_a, flag_b, eff_date, term_date
ROW_NUMBER () OVER (PARTITION BY GroupName
ORDER BY eff_date
)
-ROW_NUMBER () OVER (PARTITION BY GroupName, flag_a, flag_b)
ORDER BY eff_date
) AS output_group
OF tmp_group_test
)
SELECT GroupName, flag_a, flag_b
MIN (eff_date) AS eff_date
MAX (term_date) AS term_date
OF got_output_group
GROUP BY GroupName, flag_a, flag_b
output_group
ORDER BY GroupName
eff_date DESC
;
The result I get is
GROUP_NA F F EFF_DATE TERM_DAT
-------- - - -------- --------
Group_A Y 20110101 99991231 Y
N Group_A 20101231 20060101 N
Group_A N 20051231 20040101 Y
Group_A Y Y 20031231-20030101
Group_B N Y 99991231 20030101
which is what you asked for.
Maybe you are looking for
-
What was the problem for the 5/6 and 6/6 all email was text garbage?
all e-mails from 6/5 and 6/6 on my desk is garbage text., there is no problem on now 6/7 or 6/4 before and still the same email for those dates on my smart phone was OK to read.
-
Add - ons are not load, JS popus not appear after clicking, firebug button appears
Hello I was using Firefox 8, and then today, I noticed this not the js scripts work, the add-on does not display after a click, Firebug button at the top right is missing. Thinking that if I switch to 9 it will solve my problems, but it did not. How
-
How can restared my IMac is frozen
I have old iMac and one day I erase everything so now I want all the programs back for it iMac, Mac OS X (10.4.8
-
The pop up warning that user account control is disabled may be blocked or closed?
I have disabled UAC on my computer and I was wondering if anyone knew how to disable the periodic reminder to pop up from the Security Center remembering this fact? It is very annoying, almost as much as UAC popping up everytime I try to open or use
-
I'm unable to send some mail using windows mail. I tried to send test e-mails to my own hotmail address that works very well, but for some reason, that cannot send e-mail messages to other addresses. I tried to send them with or without attachments,