Need help in this SQL logic
Hi all
I need to create a report that shows the batch duration grouped by batch code.
The logic is that it should show. We currently have BatchId, BatchStartTime, and BatchEndTime, stored in table batch_t.
I need these BatchId group if their hours start and end times are overlapping each other as shown below.
GroupID | BatchId | BatchStartTime | BatchEndTime |
1 | 12 | 28 MARCH 13 10.03.24.000000000 AM | 28 MARCH 13 12.22.43.000000000 PM |
1 | 13 | 28 MARCH 13 10.14.38.000000000 AM | 28 MARCH 13 11.11.03.000000000 AM |
2 | 15 | 28 MARCH 13 02.19.32.000000000 PM | 28 MARCH 13 02.27.24.000000000 PM |
3 | 16 | 28 MARCH 13 03.46.23.000000000 PM | 28 MARCH 13 03.55.07.000000000 PM |
4 | 17 | 28 MARCH 13 03.55.23.000000000 PM | 28 MARCH 13 03.57.46.000000000 PM |
5 | 20 | 28 MARCH 13 04.10.53.000000000 PM | 28 MARCH 13 04.11.30.000000000 PM |
5 | 19 | 28 MARCH 13 04.02.54.000000000 PM | 28 MARCH 13 04.17.00.000000000 PM |
I'm able to find batches that overlap with the OVERLAPS operator, but I'm not able to group them as described above (see the first column).
SQL> SELECT Dense_rank() 2 over( 3 ORDER BY To_char(batchstarttime, 'DD-MON-RR HH24')) grp, 4 batchid, 5 batchstarttime, 6 batchendtime 7 FROM batch_t 8 / GRP BATCHID BATCHSTARTTIME BATCHENDTIME ---------- --------------------------------------- ------------------------------------------------- ------------------------------------------------- 1 12 28-MAR-13 10.03.24.000000 AM 28-MAR-13 12.22.43.000000 PM 1 13 28-MAR-13 10.14.38.000000 AM 28-MAR-13 11.11.03.000000 AM 2 15 28-MAR-13 02.19.32.000000 PM 28-MAR-13 02.27.24.000000 PM 3 16 28-MAR-13 03.46.23.000000 PM 28-MAR-13 03.55.07.000000 PM 3 17 28-MAR-13 03.55.23.000000 PM 28-MAR-13 03.57.46.000000 PM 4 19 28-MAR-13 04.02.54.000000 PM 28-MAR-13 04.17.00.000000 PM 4 20 28-MAR-13 04.10.53.000000 PM 28-MAR-13 04.11.30.000000 PM 7 rows selected
Tags: Database
Similar Questions
-
Hello
I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)
Primary_ID raj_id Raj_number Raj_format
1 raj rajvend 1
2 raj rajvend 1
3 raj rajvendor1 2
4 raj rajvendor1 2
5 raj rajvendor1 2
6 raj rajvendor2 3
I used under SQL to get query output as below, but has not achieved the required result:
Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)
from raj_table by sl_no asc
SL_NO raj_id raj_number raj_format primary_id
1 1 raj rajvendor 1
1 2 raj rajvendor 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 3
I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.
with t as)
Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the
Select option 2, 'raj', 'rajvend', 1 double Union all
Select 3, 'raj', 'rajvendor1', 2 double Union all
Select 4, 'raj', 'rajvendor1', 2 double Union all
Select 5, 'raj', 'rajvendor1', 2 double Union all
Select 6, 'raj', 'rajvendor2', 3 double
)
Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,
t.*
t
order by primary_id
/
PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
---------- ---------- --- ---------- ----------
1 1 raj rajvend 1
1 2 raj rajvend 1
2 3 raj rajvendor1 2
2 4 raj rajvendor1 2
2 5 raj rajvendor1 2
3 6 raj rajvendor2 36 selected lines.
SQL >
SY.
-
Hi gurus
need help with this query,
I want to display the records in the table emp
I want just the recordsSQL> Select Deptno,sal,sal/SUMSAL Percent,rn 2 From ( Select emp.*,Sum(Sal) Over() "SUMSAL",Row_number() Over(Order by sal Desc) rn 3 From emp 4 ) 5 / EMPNO DEPTNO SAL PERCENT RN --------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 7782 10 2450 .084409991 6 7499 30 1600 .055124892 7 7844 30 1500 .051679587 8 7934 10 1300 .044788975 9 7521 30 1250 .043066322 10 7654 30 1250 .043066322 11 7876 20 1100 .037898363 12 7900 30 950 .032730405 13 7369 20 800 .027562446 14 14 rows selected.
Thank youEMPNO DEPTNO SAL PERCENT RN ---------- ---------- ---------- ---------- ---------- 7839 10 5000 .172265289 1 7902 20 3000 .103359173 2 7788 20 3000 .103359173 3 7566 20 2975 .102497847 4 7698 30 2850 .098191214 5 with sum (Percent) of remaing records..... Others .420327304
Published by: SeenuGuddu on February 27, 2011 03:39with a as ( Select Empno, Deptno ,sal, sal/SUMSAL Percent, case when rn<=5 then rn else null end rnm From (Select emp.*, Sum(Sal) Over() "SUMSAL", Row_number() Over(Order by sal Desc) rn From emp) ) select case when max(rnm) is not null then to_char(max(empno)) else 'Others:' end empno, case when max(rnm) is not null then max(deptno) else null end deptno, case when max(rnm) is not null then max(sal) else null end sal, to_char(sum(percent), '90.99') percent, max(rnm) rn from a group by rnm order by rnm
EMPNO DEPTNO SAL PERCENT RN ---------------------------------------- ---------------------- ---------------------- ------- ---------------------- 7839 10 5000 0.17 1 7902 20 3000 0.10 2 7788 20 3000 0.10 3 7566 20 2975 0.10 4 7698 30 2850 0.10 5 Others: 0.42 6 rows selected
-
Need help with query SQL Inline views + Group
Hello gurus,
I would really appreciate your time and effort on this application. I have the following data set.
Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
Please ignore '-' added for clarity
I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
Here's my query. I'm a little lost.
Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
de)
Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
of the INVOICE
Sequence_id group check_date, check_number, invoice_number, vendor_number
) A, B OF INVOICE
where A.sequence_id = B.sequence_id
Thank you
NickIt seems that this is a duplicate thread - correct me if I am wrong in this case->
Need help with query SQL Inline views + Group
Kind regards.
LOULOU.
-
I need help confirming this phone I did not steal F1 * F9R
I need help confirming this phone I did not steal F1 * F9R
< personal information under the direction of the host >
Here nobody.
-
[Error number: 0x8024400A] Need help with this error... I reinstalled XP SP1 and I can't get an automatic update that's simple to install, just get this error at each time HHHHEEEELLLPPPPP! Thank you
I had the same problem. But finally found a solution. If your listing is similar to mine, then keep. XP Media Center Edition 2005 (sp2). AMD Athlon 64 x 2 Dual-Core, HP a1630n desktop computer.
Go to the HP website, search for sp37394-XP sp3 Upgrade utility Microsoft for systems equipped with AMD processors.
I had the same 0 x 80240036, 0x8024400a error, but realize my problem was really get manually downloaded sp3 and installed without continue loop crashing and not error messages.
-
Is there a default value for the color management in PSE10? Beautiful photos from iPhoto, but blur with elements. I need help with this before as I consider that the upgrade to PSE13 and beyond.
Printing which forms an angle seems ok, but one that is horizontally seems faded, incomplete.
I was wondering if I saved a layer somewhere and set it as a default value.
If you group the layers, you will be left with a single layer, thus spreading your concern.
Suggest that you do the following:
- Make sure you have the latest drivers for your printers
- Reset the default preferences.
Hold the Alt, Ctrl + Shift keys when you click the icon to open the items. When asked if you want to delete the settings file, say Yes.
Items nearby and let regenerate the file.
-
Need help with this gallery of xml!
I have build a gallery but its very simple... There are pictures of the xml file.
I have attached all the zip files.
I just want two things if anyone can help.
first of all when I press the next button, he's going to the next image, but without effect. It just displays the following image... I want to incorporate the effect of dragging when the image is changed to another.
and secondly, I want to use the AutoPlay feature.
Once swf starts images came one by one with a vertical drop of a few seconds.
Thanks in advance... I really need help with this..!
For the look of sliding effect using the actionscript class Tween. Allows you to create motion tweens using the code. The example below will be tween property _x of the instance named anObject from 0 to 300 in 3 seconds...
import classes before using
Import mx.transitions.Tween;
Import mx.transitions.easing.Regular;TW var = new Tween (anObject, "_x", Regular.easeIn, 0, 300, 3, true);
To implement an enforcement function auto you need to import all the images first, in the order, then you will need to use form any controlled timer, such as setInterval (with clearInterval not to need) in order to have things turn on automatically by some part-time
-
Hi all
I need to write a sql that retrieves data from the status table and check for this time in the ESHIFT table if the flag was or not. If is there, then it will keep the record as it is Furthermore, there
did not understand at the time the flag was N suppose ESHIFT table has one record where you N 13:00:01-13:30 then the status register which is 13:00-13:59 min 59 s, we should get 13:00 - 13: records of 00:00 1 and 2 of 13:30:01-13:59 min 59 s
create table ESHIFT (From_date date, date, to_date, flag varchar2 (2));
insert into ESHIFT values (' 1 February 12 09:00 ", February 1, 12 13:20 ', 'Y');
insert into ESHIFT values (' 1 February 12 13:20:01 ", 1 February 12 13:30 ',' don't);
insert into ESHIFT values (' 1 February 12 13:30:01 ", February 1, 12 16:00 ', 'Y');
SELECT * from eshift;
create table status (date of From_date, to_date date, status number);
insert into values of status (1 February 12 11:00 ', February 1, 12 12:00 ', 1);
insert into values of status (1 February 12 12:00:01 ', February 1, 12 12:20 ', 2);
insert into status values ("1 February 12 12:20:01", 1 February 12 12:59:59 ', 1);
insert into status values ("1 February 12 13:00", February 1, 12 13:59:59 ', 1);
insert into status values ("1 February 12 14:00", February 1, 12 14:59:59 ', 2);
SELECT * STATUS;
In the case above should get sql
1 FEBRUARY 12 11:00 1ST FEBRUARY 12 12:00 1
FEBRUARY 1ST, 12 12:00 1ST FEBRUARY 12 12:20 2
FEBRUARY 1ST, 12 12:20:01, 1 FEBRUARY 12 12:59:59 1
FEBRUARY 1ST, 12 13:00 1ST FEBRUARY 12 13:20 1
FEBRUARY 1ST, 12 13:30 1 FEBRUARY 12 13:59:59 1
FEBRUARY 1ST, 12 14:00 1 FEBRUARY 12 14:59:59 2
It will be really great if someone can help me how I can get the desired result.
Thank you very much in advance.
Please provide instructions creating table and data. It makes it so much easier to answer.
I think you want:
Select (s.from_date, e.from_date) greatest from_date, less (s.to_date, e.to_date) to_date, s.status
s status e eshift join on s.from_date < e.to_date="" and="" s.to_date=""> e.from_date and e.flag = 'Y '.
order by 1
-
Need help with PL/SQL query complex
I need help with a query that need access to data from 3 tables. That's what I did
I created 3 tables
CREATE TABLE post_table
(
post_id varchar (20),
datepost DATE,
KEY (post_id) elementary SCHOOL
) ;
CREATE TABLE topic
(
TOPIC_ID varchar (20),
name varchar (20),
PRIMARY KEY (topic_id)
);
CREATE TABLE blogpost_table
(
TOPIC_ID varchar (20),
post_id varchar (20),
PRIMARY KEY (topic_id, post_id);
FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
);
Now, I inserted a few values in these tables as
INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
INSERT INTO VALUES subject ("t1", "baseball");
INSERT INTO category VALUES ('t2', 'football');
INSERT INTO blogpost_table VALUES ("t1", "p1");
INSERT INTO blogpost_table VALUES ('t1', 'p3');
INSERT INTO blogpost_table VALUES ("t1", "p4");
INSERT INTO blogpost_table VALUES ('t1', 'p5');
INSERT INTO blogpost_table VALUES ('t2', 'p2');
INSERT INTO blogpost_table VALUES ('t2', 'p6');
INSERT INTO blogpost_table VALUES ("t2", "p7");
I'm launching SQL queries on the table in this topic.
I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.
Can someone please help me to write this query?
Thank you
Published by: user11994430 on October 9, 2009 07:24Thanks for the test of the configuration!
SQL>SELECT t.NAME, COUNT(*) 2 FROM topic t, blogpost_table b, post_table p 3 WHERE b.topic_id = t.topic_id 4 AND p.post_id = b.post_id 5 AND p.datepost >= DATE '2009-07-01' 6 AND p.datepost < DATE '2009-08-01' 7 GROUP BY t.NAME 8 ORDER BY COUNT(*) desc; NAME COUNT(*) -------------------- ---------- baseball 2 soccer 2
HTH, Urs
-
1 wmpscfgs.exe is this a virus?
http://i259.Photobucket.com/albums/hh282/chips909/pop-up.PNG
2 svchost.exe is a virus?
http://i259.Photobucket.com/albums/hh282/chips909/pop-up02.PNG
Well, I got some virus lately. :/ av.exe and much more.
I had a few problems if you could help me.
Theres been more there just very quickly.This is my another Post. I really need help.
This virus has turned off my registry Variables. I get the error message: «Registry editing has been disabled by your Adimn.»
How can I fix?--------------------
Csrss.exe - Virus?
Lsass.exe - Virus?
mbptn.exe - Virus?
sttray.exe - Virus?
Smss.exe - Virus?
Svchost.exe - Virus?
Winlogon.exe - Virus?
Spoolsv.exe - Virus?
bgsvcgen.exe Virus?
jqs.exe - Virus
MDM.exe - Virus?
--------------------Please answer this can't is\isn a Virus that I have just listed.
Thank you
-Morse groovy-Csrss.exe - Virus?
normally no; See http://www.neuber.com/taskmanager/process/csrss.exe.html
Lsass.exe - Virus?normally no; See http://www.neuber.com/taskmanager/process/lsass.exe.html
mbptn.exe - Virus?normally no; See http://www.neuber.com/taskmanager/process/mpbtn.exe.html
sttray.exe - Virus?No.; See above site (sigmatel audio)
Smss.exe - Virus?normally no; Well that eventually check infection http://www.neuber.com/taskmanager/process/smss.exe.htmlSvchost.exe - Virus?No.; Generic Host Process for Win32 Services
Winlogon.exe - Virus?No.; logon XP
Spoolsv.exe - Virus?No.; service of ms coils
bgsvcgen.exe Virus?No.; TMPGEnc DVD with DivX Authoring Authorr3
jqs.exe - VirusNo.; Java quick start
MDM.exe - Virus?No; machine debug manager -
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.
-
I am trying to write the SQL for a single recordset.
I have a table with all the info from the standard article and an item_colorID.
I have a table with 2 columns, item_colorID and color_ID color_lookup
I have a table with 2 columns, color_ID colors and color
I want to join the tables and filter it so that a repeat region shows dynamic data by the name of article, thumb, description, price
and also a dynamic list/menu populated by color
filtered so that each element is in the list/menu only available element colors.
I have tried different variations of this sql
SELECT * items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
but the list/menu shows each color choice, multiplied by the number of items in this color
That is to say white will show 80 + times.
Thanks for your help,
Jim balthrop
Hi JB, I think I understand the situation, but of course, I'm not familiar with the interface of the cart software you are using. It seems that you will not be able to use the choice "research from the recordset" because the color is a different Recordset. You can't really understand the color in the main recordset because it would cause the main repeating region show the item once for each available color, which is not what you want.
I also see that the drop-down color is in its own form. If you have placed this process in the main form, would be the behavior recoginize it and treat it differently? In other words, the cart accepts entry options outside the main form element it uses:
I don't know that the shopping cart software contains other methods to add to the cart you can be forced to use.
What shopping cart software are you helping? They have a forum which you could get more targeted assistance?
-
Need help with this problem please
Hi all
I have 2 tables and I am runnig the following query against it:
and get the following dataset:select t1.ID_NBR, t1.START_DATE,t1.END_DATE,t1.SAMPLE_ID,t2.END_INTV_TIME,t2.CIN_DATA_ID from sample t1,weekend t2 where t1.SAMPLE_ID=t2.SAMPLE_ID_1 and t1.WEEKEND_FLAG='Y' and t1.SITE_ID_NBR='000097117011'
What I wanted was to add 2 columns to all data above, the reason is the dataset above has 72 files, one file per hour for 3 days from Friday 01:00 and ending the Sunday i 2400, but all have in all of the above data is just the date of beginning and end, so I created the following query to add the columns :ID_NBR START_DATE END_DATE SAMPLE_ID END_INTV_TIME CIN_DATA_ID 97117011 91908 92108 143493 100 131834 97117011 91908 92108 143493 200 131835 97117011 91908 92108 143493 300 131836 97117011 91908 92108 143493 400 131837 97117011 91908 92108 143493 500 131838 97117011 91908 92108 143493 600 131839 97117011 91908 92108 143493 700 131840 97117011 91908 92108 143493 800 131841 97117011 91908 92108 143493 900 131842 97117011 91908 92108 143493 1000 131843 97117011 91908 92108 143493 1100 131844 97117011 91908 92108 143493 1200 131845 97117011 91908 92108 143493 1300 131846 97117011 91908 92108 143493 1400 131847 97117011 91908 92108 143493 1500 131848 97117011 91908 92108 143493 1600 131849 97117011 91908 92108 143493 1700 131850 97117011 91908 92108 143493 1800 131851 97117011 91908 92108 143493 1900 131852 97117011 91908 92108 143493 2000 131853 97117011 91908 92108 143493 2100 131854 97117011 91908 92108 143493 2200 131855 97117011 91908 92108 143493 2300 131856 97117011 91908 92108 143493 2400 131857 97117011 91908 92108 143493 100 131858 97117011 91908 92108 143493 200 131859 97117011 91908 92108 143493 300 131860 97117011 91908 92108 143493 400 131861 97117011 91908 92108 143493 500 131862 97117011 91908 92108 143493 600 131863 97117011 91908 92108 143493 700 131864 97117011 91908 92108 143493 800 131865 97117011 91908 92108 143493 900 131866 97117011 91908 92108 143493 1000 131867 97117011 91908 92108 143493 1100 131868 97117011 91908 92108 143493 1200 131869 97117011 91908 92108 143493 1300 131870 97117011 91908 92108 143493 1400 131871 97117011 91908 92108 143493 1500 131872 97117011 91908 92108 143493 1600 131873 97117011 91908 92108 143493 1700 131874 97117011 91908 92108 143493 1800 131875 97117011 91908 92108 143493 1900 131876 97117011 91908 92108 143493 2000 131877 97117011 91908 92108 143493 2100 131878 97117011 91908 92108 143493 2200 131879 97117011 91908 92108 143493 2300 131880 97117011 91908 92108 143493 2400 131881 97117011 91908 92108 143493 100 131882 97117011 91908 92108 143493 200 131883 97117011 91908 92108 143493 300 131884 97117011 91908 92108 143493 400 131885 97117011 91908 92108 143493 500 131886 97117011 91908 92108 143493 600 131887 97117011 91908 92108 143493 700 131888 97117011 91908 92108 143493 800 131889 97117011 91908 92108 143493 900 131890 97117011 91908 92108 143493 1000 131891 97117011 91908 92108 143493 1100 131892 97117011 91908 92108 143493 1200 131893 97117011 91908 92108 143493 1300 131894 97117011 91908 92108 143493 1400 131895 97117011 91908 92108 143493 1500 131896 97117011 91908 92108 143493 1600 131897 97117011 91908 92108 143493 1700 131898 97117011 91908 92108 143493 1800 131899 97117011 91908 92108 143493 1900 131900 97117011 91908 92108 143493 2000 131901 97117011 91908 92108 143493 2100 131902 97117011 91908 92108 143493 2200 131903 97117011 91908 92108 143493 2300 131904 97117011 91908 92108 143493 2400 131905
And the problem I have now is instead of 72 for 3 days I get only 71 and time 2400 is paased on the next day, I tried to use CEIL instead and ended up getting 48 reocrds instead, the following dataset is when I used the above querySELECT * FROM (SELECT t.*, TO_CHAR (TO_DATE (start_date, 'mmddrr') + TRUNC (rn / 24), 'Day' ) AS weekday, TO_CHAR (TO_DATE (start_date, 'mmddrr') + TRUNC (rn / 24), 'mmddyy' ) AS next_date FROM (SELECT t1.id_nbr, t1.start_date, TO_CHAR (TO_DATE (t1.start_date, 'mm/dd/yy'), 'fmDay' ) AS start_day, t1.end_date, TO_CHAR (TO_DATE (t1.end_date, 'mm/dd/yy'), 'fmDay' ) AS end_day, t2.sample_id_1, t2.cin_data_id, t2.end_intv_time, ROW_NUMBER () OVER (PARTITION BY t2.sample_id_1 ORDER BY t2.cin_data_id) AS rn, COUNT (t2.cin_data_id) OVER (PARTITION BY t2.sample_id_1) AS cnt, t1.weekend_flag FROM sample t1, weekend t2 WHERE t1.sample_id = t2.sample_id_1 AND t1.weekend_flag = 'Y') t) WHERE TRIM (weekday) IN ('Friday', 'Saturday', 'Sunday') AND nbr = '000097117011'
Need help please.ID_NBR START_DATE START_DAY NEXT_DATE WEEKDAY END_DATE END_DAY SAMPLE_ID CIN_DATA_ID END_INTV_TIME 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131848 1500 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131849 1600 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131850 1700 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131851 1800 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131852 1900 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131853 2000 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131854 2100 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131855 2200 97117011 91908 Friday 91908 Friday 92108 Sunday 143493 131856 2300 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131857 2400 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131858 100 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131859 200 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131860 300 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131861 400 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131862 500 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131863 600 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131864 700 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131865 800 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131866 900 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131867 1000 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131868 1100 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131869 1200 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131870 1300 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131871 1400 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131872 1500 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131873 1600 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131874 1700 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131875 1800 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131876 1900 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131877 2000 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131878 2100 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131879 2200 97117011 91908 Friday 92008 Saturday 92108 Sunday 143493 131880 2300 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131881 2400 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131882 100 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131883 200 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131884 300 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131885 400 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131886 500 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131887 600 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131888 700 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131889 800 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131890 900 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131891 1000 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131892 1100 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131893 1200 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131894 1300 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131895 1400 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131896 1500 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131897 1600 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131898 1700 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131899 1800 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131900 1900 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131901 2000 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131902 2100 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131903 2200 97117011 91908 Friday 92108 Sunday 92108 Sunday 143493 131904 2300
Thank youHello
Hours in a range of 0 to 23 hours day after midnight. You count from 1, not 0, so the 24th hour (from Friday) is actually from 00:00 on Saturday, and the 72nd hour is 00:00 Monday, that you are not counting in the WHERE clause.
Maybe when you calculate tn, you might simply subtract 1:
SELECT * FROM (SELECT t.*, TO_CHAR (TO_DATE (start_date, 'mmddrr') + TRUNC (rn / 24), 'Day' ) AS weekday, TO_CHAR (TO_DATE (start_date, 'mmddrr') + TRUNC (rn / 24), 'mmddyy' ) AS next_date FROM (SELECT t1.id_nbr, t1.start_date, TO_CHAR (TO_DATE (t1.start_date, 'mm/dd/yy'), 'fmDay' ) AS start_day, t1.end_date, TO_CHAR (TO_DATE (t1.end_date, 'mm/dd/yy'), 'fmDay' ) AS end_day, t2.sample_id_1, t2.cin_data_id, t2.end_intv_time, ROW_NUMBER () OVER (PARTITION BY t2.sample_id_1 ORDER BY t2.cin_data_id) - 1 -- Added AS rn, COUNT (t2.cin_data_id) OVER (PARTITION BY t2.sample_id_1) AS cnt, t1.weekend_flag FROM sample t1, weekend t2 WHERE t1.sample_id = t2.sample_id_1 AND t1.weekend_flag = 'Y') t) WHERE TRIM (weekday) IN ('Friday', 'Saturday', 'Sunday') AND nbr = '000097117011'
To view the actual end time, add one hour before posting.
What happens if you are missing a row for some reason any? Just using ROW_NUMBER won't take the missing line into account. It would be preferable to derive the time of the end_intc_timecolumn. Of course, it would be even better to store the date and time ending in a DATE column all the way.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
You must not post a lot of data: 6 hours, ending at midnight Monday, should be enough to show the problem and its solution.Always tell what version of Oracle you are using.
-
Need help with this pl/sql code
Hello
It is showing an error sql command not properly ended... where FLX_TEXTTRAN802003. SPTEXTINSERT
is a package... help me please
BEGIN DECLARE v_TextID NUMBER :=0; I_LanguageID NUMBER := 1033; v_count number; e_error EXCEPTION; BEGIN --INsert into text FLX_TEXTTRAN802003.SPTEXTINSERT (io_id => v_TextID, i_type => N'', i_lastupdateon => cob_f_getutc, i_lastupdatedby => 'NGMESSystem', i_createdon => cob_f_getutc, i_createdby => 'NGMESSystem' ); -- Insert into TEXT_TRANSLATION FLX_TEXTTRAN802003.SPTEXTTRANINSERT (i_TextID => v_TextID, I_LanguageID => I_LanguageID, i_short => 'CUSTOMER', i_medium => 'CUSTOMER', i_extended => 'CUSTOMER', i_lastupdateon => cob_f_getutc, i_lastupdatedby => 'NGMESSystem', i_createdon => cob_f_getutc, i_createdby => 'NGMESSystem' ); select count(*) into v_count from characteristic_class where name='CUSTOMER' if v_count = 0 then Insert into FLXUSER.characteristic_class (ID, NAME, TEXTID, REFERENCEID, LASTUPDATEON, LASTUPDATEDBY, CREATEDON, CREATEDBY, ACTIVE, LASTDELETEON, LASTDELETEDBY, LASTREACTIVATEON, LASTREACTIVATEDBY, ARCHIVEID, LASTARCHIVEON, LASTARCHIVEDBY, LASTRESTOREON, LASTRESTOREDBY, ROWVERSIONSTAMP) Values (SEQ_CHARACTERISTIC_CLASS.nextval, 'CUSTOMER', v_TextID, NULL, NULL, NULL, TO_DATE('11/05/2012 16:49:05', 'MM/DD/YYYY HH24:MI:SS'), 'SYSTEM', 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1); commit; ELSE Raise e_error; END IF; EXCEPTION when e_error then dbms_output.put_line('data already exist'); end;
Hello
next to what Frank says, the following line:
select count(*) into v_count from characteristic_class where name='CUSTOMER'
missing semicolon at the end:
select count(*) into v_count from characteristic_class where name='CUSTOMER' ;
Also the BEGIN initial until the DECLARE is unmatched (no corresponding END).
You can remove it.Kind regards.
AlPublished by: Alberto Faenza on November 6, 2012 16:24
Maybe you are looking for
-
How do you improve original IPad to IOS version newer than 5.1.1
I have an original IPad (IPad 1), I want to give to a friend. I have reset everything, but when I upgraded the operating system, the latest version that it will move to East 5.1.1. This version won't let me download apps. I get an error when you t
-
Satellite l.660-106 with Windows 7 has stopped booting upward
My l.660 was for a long time, yesterday, during which he downloaded the updates of Windows. This morning, it wouldn't boot. Unfortunately, I have not prepared recovery disc and do not have the disc of Windows 7 computer was purchased with the system
-
Email attachments-JPG PHOTOS - Cnnot transferred to the Viewer.
I opened the photos in the body of my email and a box popped up as I started IMAGE transfer who asked if I wanted to use the easy batch transfer of Firefox photos. I clicked on ok. but now when I record (it is a firefox-htm document) to the image vie
-
iOS app how to set unique user name
Is it possible to store a user name and other details in an ios app on the first run of the application through user input and store this data constantly without another user input for the lifetime of the application? using basic data.
-
Pavilion g6-2278dx: System Recovery dvd kit fails
My hard drive died and I was able to recover most of the images of the files before it failed completely. The patition of recovery was also damaged and I failed to make recovery disks. I installed a new and bigger hard drive and ordered the DVD and t