Logical year SQL help...
Hi, can anyone suggest a better way to please...I'm looking to calculate the number of policies here and I want to group counties datewise/yearwise as below:
(1) County policies added during the month of the date of entry into
(2) policies County added since (1 month to 1 year)
(3) policies County added in the second year (i.e. between 1 year and 2nd year)
(4) County of policies are complemented by year 2 (i.e. > 2 years)
Below is the example sql with that I came:
(1) select count (plcy_id)
from table_1 b
where
b.PLCY_EFDT < = b.ORIGINAL_PLCY_EFDT + 30
(2) select count (plcy_id)
from table_1 b
where
b.PLCY_EFDT (b.ORIGINAL_PLCY_EFDT + 30) AND (b.ORIGINAL_PLCY_EFDT + 360)
(3) select count (plcy_id)
from table_1 b
where
b.PLCY_EFDT (b.ORIGINAL_PLCY_EFDT + 360) AND (b.ORIGINAL_PLCY_EFDT + 720)
Count (plcy_id) select 4)
from table_1 b
where
b.PLCY_EFDT > = b.ORIGINAL_PLCY_EFDT + 720
Please let me know if there is any way to rewrite the query... Thanks for the help.
better to use the add_month function
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions004.htm#SQLRF00603
Tags: Database
Similar Questions
-
When I started to update my iphone to ios 10 and watch 3.0, cannot already display the pictures of my watch. Logo of loading only. And he thinks it will take a hayss of 1000 years. Help, please
Hello
If the software on your watch is being updated, leave your watch and your iPhone until the process is complete (including the not remove your watch on the charger):
-
How can I get the logic of sql from the catalog or the obiee Manager
I try to get the logic sql behind a report. Can someone help me how to get sql obiee presentation services or from Catalog Manager
Hello
Addition to the response of Srini, you know that there is a new view in g 11 responses to display SQL logic? Just choose in the analysis-> results-> new view-> other-> SQL-> Standard SQL logic views.
I hope this helps.
Diakité
-
RDB. Oracle with SQL help
Hi all the gurus.
I m NOT a guru :-(
It's my problem.
I have 2 tables with same columns
sales_calculation_text and tmp_calculation_text.
Columns of the SALES_CALCULATION_TEXT table: (and tmp...)
Column name Data Type Domain
----------- --------- ------
STOCK_ID TANK (2)
DEAL_NO CHAR (10)
CALC_VERSION_NO SMALLINT
TEXT_ROW_TYPE TANK (25)
TEXT_ROW_NO SMALLINT
TEXT_ROW TANK (80)
The SALES table contains about 800000 lines and is used by the application.
Every night the TMP table is fallen, recreated and populated by some infiles. After the table TMP contains the population every night
some exactly identical rows in the SALES table, a few new lines and a few lines with update TEXT_ROW.
The infiles contains:
new DEAL_NO of information
old DEAL_NO with TEXT_ROW update on the existing test_rows (won´t be moved to SALES-table with todays SQL...)
After that TMP table is re-created/filled the following sql code moves the data:
INSERT INTO sales_calculation_text
SELECT * FROM t tmp_calculation_text WHERE
NOT EXIST
(SELECT * FROM sales_calculation_text where)
a.stock_id = t.stock_id and
a.deal_no = t.deal_no and
a.calc_version_no = t.calc_version_no and
a.text_row_type = t.text_row_type and
a.text_row_no = t.text_row_no);
COMMIT;
This has been very good since the beginning of the application a few years ago, but recentlly that the infiles contains updated TEXT_ROW that will not be updated
by the sql...
I don't have the skills to write SQL - someone please HELP me...
BR
BjornrAfter INSERTING run this
UPDATE sales_calculation_text a SET text_row = (select text_row FROM tmp_calculation_text t WHERE a.stock_id=t.stock_id and a.deal_no=t.deal_no and a.calc_version_no=t.calc_version_no and a.text_row_type=t.text_row_type and a.text_row_no=t.text_row_no) WHERE 1=(SELECT count(0) FROM tmp_calculation_text t WHERE a.stock_id=t.stock_id and a.deal_no=t.deal_no and a.calc_version_no=t.calc_version_no and a.text_row_type=t.text_row_type and a.text_row_no=t.text_row_no); COMMIT;
Max
-
SQL Help: selection of tickets without open tasks
Hi gurus,
I'm new to SQL. I need your help for a script where I pick up tickets without open tasks.
Say, here is the table of tasks
Table: task
------------------------------
| TicketID | TaskID. TaskStatus.
------------------------------
| 1. 1. O |
| 1. 2. O |
| 1. 3. O |
| 2. 4. C |
| 2. 5. C |
| 3. 6. C |
| 3. 7. O |
------------------------------
The query should return the ticketid (s) with all its taskstatus = 'C '.
Any help would be much appreciated.
Thank youHello
surya_vus wrote:
Frank,Your query will exclude other State of the task?
Try it and see!
If, in your real problem, the relevant information are spread over three tables, then join them.
If there is a condition of additional, based on reason, then add that. The WHERE clause is the most logical place.
If you are interested in taskstatus in 'C' or 'F', then test for one or the other.If the GROUP OF... HAVING solution is:
SELECT ti.ticketid FROM ticket ti JOIN task ta ON ti.ticketid = ta.ticketid JOIN taskstatus st ON ta.taskstatusid = st.taskstatusid WHERE ti.reason = 'C' GROUP BY ticketid HAVING COUNT (*) = COUNT ( CASE WHEN st.taskstatus IN ('C', 'F') THEN 1 END );
-
When you use Roland FC300 footswitch to control transport LOGIC, all midi keyboard USB (UMA25s) notes do not reach the logic.
They are visible using MIDI Monitor s/w so reach the OS X - but do not make SENSE.
I tried the function of the environment of the logic and the double check OS X Midi Setup but no difference statistically.
I would appreciate any help on how to proceed.
Thank you
Paddy
I do not understand your post. Your use the FC300 to control logic - how is it connected? Is it plugged into the keyboard via middle or did you connect to logic directly via a midi interface? (sense are the keyboard and the FC300 connected independently.
When you say midi notes reached illogical (those transmitted by the FC300 or those via the USB keyboard do you mean?).
First thing to do is to circumvent the control surfaces to exclude...
Then, the control screen the custom value and see if data midi reached logical... If his hitting the midi monitor 99.9% sure it is hitting logic.
-
Problem SQL HELP during the installation of aviation the interactive dvd course!
try to download interactive dvd Aviation course and be sktc kingschool SQL error does not exist... Check the State of SQL express instance and I install the classes I get a SsRestart occurred must close and send error report... Any help would be great! Help!
I suggest that you contact the manufacturer of the interactive DVD software to help get the program installed.
They would be better able to help with your problem.
Thank you
Marilyn
-
SQL Help: Add flag for several tables
Hello
I have an existing SQL as follows:
Select the storeId field,
(select case when count (1) > 0 0 otherwise then 1 end)
of tb_bbb
where tb_bbb.id = tb_base.baseId) AS conInd
of tb_base;
I would now add the table tb_ccc for the value of conInd. I try the following SQL:
Select the storeId field,
(select case when count (1) > 0 0 otherwise then 1 end)
Of
(select tb_bbb.id where tb_bbb.id = tb_base.baseId)
Union
Select tb_ccc.id where tb_ccc.id = tb_base.basdId) AS conInd
of tb_base;
However, it does not work. Any idea on this SQL? Thanks for your help!
Hello
Here is another way, which may be more effective because it uses EXISTS (which can quit smoking as soon as it finds a match) instead of COUNT (who continues to go, so he can tell you if there are 999 or 1000 matches, even if you don't care to).
SELECT storeid
CASE
WHEN THERE IS)
SELECT 1
OF tb_bbb
WHERE bbb_id = m.baseid
) 1 THEN
WHEN THERE IS)
SELECT 1
OF tb_ccc
WHERE ccc_id = m.baseid
) 1 THEN
0 OTHERWISE
END AS conlnd
OF tb_base m
;
-
Hi all
I need correct column value serNo to the right as a result. It suppose to be the sequence number for each storeID. Any suggestion on the SQL?
create table test1 (storeID number (5), number serNo (5));
insert into table test1 values (100, 1);
insert into table test1 values (200, 1);
insert into table test1 values (100, 1);
insert into table test1 values (200, 1);
insert into table test1 values (100, 1);
insert into table test1 values (100, 1);
I want to have the following results in test1 after conversion:
1 100
2 100
3 100
4 100
1 200
2 200
Thank you
Hello
942572 wrote:
Hi all
I need correct column value serNo to the right as a result. It suppose to be the sequence number for each storeID. Any suggestion on the SQL?
create table test1 (storeID number (5), number serNo (5));
insert into table test1 values (100, 1);
insert into table test1 values (200, 1);
insert into table test1 values (100, 1);
insert into table test1 values (200, 1);
insert into table test1 values (100, 1);
insert into table test1 values (100, 1);
I want to have the following results in test1 after conversion:
1 100
2 100
3 100
4 100
1 200
2 200
Thank you
Use the ROW_NUMBER analytic function to generate the new sernos, like this:
MERGE INTO dst test1
WITH THE HELP OF)
SELECT ROWID AS r_id
ROW_NUMBER () OVER (PARTITION BY storeid
ORDER BY NULL
) AS serno
OF test1
) src
ON (summer time. ROWID = src.r_id)
WHEN MATCHED THEN UPDATE
SET dst.serno = src.serno
;
Really, your table must have a primary key. Because it's not working, I had to ROWID allows you to uniquely identify the lines.
-
SQL Help: How to collect summary number in group by?
HelloI have the following table:
create table tb_class_info (classNbr number (5), number (2) of ClassType, classTeacherNbr number (4));
insert into tb_class_info values (101, 1, 12);
insert into tb_class_info values (001, 2, 12);
insert into tb_class_info_values (001, 2, 13);
insert into tb_class_info_values (002, 2, 12);
insert into tb_class_info_values (002, 2, 12);
I would like to get statistics on the cnt, cnt for classType = 2 classTeacherNbr classNbr. I expect to have the following results:
classNbr classType2Cnt classTeacherCnt
101 0 0
001 2 2
002 2 1
The following SQL code I use:
SELECT classNbr,
SUM (CASE when classType = 2 THEN 1 ELSE END 0) as classTypeCnt,
SUM (CASE when classType = 2 SO unique classTeacherNbr ELSE 0 END) as classTeacherCnt
OF tb_class_info
GROUP BY classNbr;
However, I have the ' ORA-00905: lack of keyword ' error. Any suggestion on this subject?
Thanks for your help!
Select classnbr
sum (case when classtype = 2 then 1 end)
, count (distinct case when classtype = 2 then teachernbr end)
of tb_class_into
Classnbr group;
-
I'm pretty new in pl/sql, I want to update a column with the next number.
Here's an example-
Table: political
Policy_no Sequence Company_name 101 0 ABC PTY LTD. 101 0 XYZ PTY LTD 103 0 Test PTY LTD 104 0 Test101 PTY LTD 101 0 Pearl PTY LTD 104 0 MyZore pty ltd I would get the date in the following format
After Update - table
Policy_no Sequence Company_name 101 1 ABC PTY LTD. 101 2 XYZ PTY LTD 101 3 Pearl PTY LTD 103 1 Test PTY LTD 104 1 Test101 PTY LTD 104 2 MyZore pty ltd Basically, I want to update the column sequence based on the Policy_No group.
Can someone please help.
>
Basically, I want to update the column sequence based on the Policy_No group.
>
This query will show you how to generate the values you need.
>
Select empno, deptno, row_number() over (partition by deptno) myRow arrested by deptno from EMP
EMPNO, DEPTNO, MYROW
7782,10,1
7839,10,2
7934,10,3
7566,20,1
7902,20,2
7876,20,3
7369,20,4
7788,20,5
7521,30,1
7844,30,2
7499,30,3
7900,30,4
7698,30,5
7654,30,6
>
According to the number of rows in the table, you might be better to create a new table using DEC or a query like this.
-
Multiple Table join without loss of data - SQL help
Hello
I have the following tables 3 employee as indicated in the scripts below, please help in writing SQL that connects all these 3 tables and displays the output as shown below
Required output
EMP ID Loc Value 1 Value 2 Value 3
1 A 3 1 6
1 B 4 9 null
Value null null 1 Wh 8
2 Z 4 9 null
3 R 0 null 1
4 Y 1 null null
5 O 7 7 null
Value null null 5 Wh 5
6 M 7 null 7
6 B null null 8
/ * Create Tables * /.
Create table Emp1 (Empid number, Loc Varchar2 (10), Value_1 number);
Create the Emp2 Table (Empid number, Loc Varchar2 (10), Value_2 number);
Create table emp3 (empid number, loc varchar2 (10), Value_3);
/ * Insert Scripts * /.
Insert Into Emp1 Values (1, 'A', 3);
Insert Into Emp1 Values (2, 'Z', 4);
Insert Into Emp1 Values (3, 'R', 0);
Insert Into Emp1 Values (4, 'Y', 1);
Insert Into Emp1 Values (5, 'o', 7);
Insert Into Emp1 Values (6, am', 7);
Insert Into Emp2 Values (1, 'A', 1);
Insert Into Emp2 Values (1, 'B', 4);
Insert Into Emp2 Values (1, 'Wh', 8);
Insert Into Emp2 Values (2, 'Z', 9);
Insert Into Emp2 Values (5, 'o', 7);
Insert Into Emp2 Values (5, 'Wh', 5);
Insert Into Emp3 Values (1, 'A', 6);
Insert Into Emp3 Values (1, 'B', 9);
Insert Into Emp3 Values (3, 'R', 1);
Insert Into Emp3 Values (6, am', 7);
Insert Into Emp3 Values (6, 'B', 8);
Commit;
Thank you
VarunLike this?
SQL> select nvl(e.empid, e3.empid) empid 2 , nvl(e.loc, e3.loc) loc 3 , e.value_1 4 , e.value_2 5 , e3.value_3 6 from ( 7 select nvl(e1.empid, e2.empid) empid 8 , nvl(e1.loc, e2.loc) loc 9 , e1.value_1 10 , e2.value_2 11 from emp1 e1 12 full join emp2 e2 13 on e1.empid = e2.empid 14 and e1.loc = e2.loc 15 ) e 16 full join emp3 e3 17 on e.empid = e3.empid 18 and e.loc = e3.loc 19 order 20 by empid 21 , loc 22 / EMPID LOC VALUE_1 VALUE_2 VALUE_3 ---------- ---------- ---------- ---------- ---------- 1 A 3 1 6 1 B 4 9 1 Wh 8 2 Z 4 9 3 R 0 1 4 Y 1 5 O 7 7 5 Wh 5 6 B 8 6 M 7 7 10 rows selected. SQL>
-
SQL help. Identify changes to a field.
Greetings!
PS/SQL is not an option for me. I need help to use SQL, if possible for the following scenario.
Oracle 10G.
Table: JOB_DATA
EMPLID, DATE_EFF, DEPTID, JOBCODE
100, 01/11/2012, 34567, MNG
100, 01/10/2012, 34567, SUP
100, 01/09/2012, 28967, MNG
100, 15/08/2012, 28967, SUP
100,6/30/2012,15879, MNG
I need to get the following records only, in other words, every time that changes in the Department ID.
100, 01/10/2012, 34567, SUP
100, 15/08/2012, 28967, SUP
100,6/30/2012,15879, MNG
Thanks in advance.It looks like you want something like
SELECT * FROM (SELECT j.*, lag(deptid) over (partition by emplid order by date_eff) prior_deptid FROM job_data j) WHERE prior_deptid IS NULL OR prior_deptid != deptid
Justin
-
Hello
I have a requirement where I need to write AGA10.dll on Oracle PL SQL code. But I feel very difficult to understand this logic AGA10 which is in C++ and convert it into Oracle PL SQL API.
Is there anything that we can call this dll directly in our SQL PL stored package?
(* AGA10 *-American Gas Association report No 10 to calculate the compressibility of the gas and the speed of sound)
Kind regards
AlkaHi, as stated, this is the wrong forum. It's the Oracle Designer CASE tool that is forum. You need the place of SQL & PL/SQL
Don't have an idea why this place is not in the same leg as a Designer
Published by: Johnreardon on April 6, 2012 01:53
-
Hello
I have the following table
I need to write the sql query to get the following resultsEmployeeID | ProjectID | Tasks EMP 01 | PID 01 | 5 EMP 01 | PID 01 | 1 EMP 01 | PID 02 | 8 EMP 01 | PID 03 | 9 EMP 02 | PID 01 | 7 EMP 02 | PID 02 | 4 EMP 02 | PID 02 | 3 EMP 03 | PID 04 | 1 EMP 04 | PID 04 | 8 EMP 04 | PID 04 | 7
Any help?EmployeeID | ProjectID | EmpTasks | ProjectTasks EMP 01 | PID 01 | 23 | 6 EMP 01 | PID 01 | 23 | 6 EMP 01 | PID 02 | 23 | 8 EMP 01 | PID 03 | 23 | 9 EMP 02 | PID 01 | 14 | 7 EMP 02 | PID 02 | 14 | 7 EMP 02 | PID 02 | 14 | 7 EMP 03 | PID 04 | 1 | 1 EMP 04 | PID 04 | 15 | 15 EMP 04 | PID 04 | 15 | 15
Thank youThis should do it:
WITH t AS (SELECT 'EMP 01' EmployeeID, 'PID 01' ProjectID, 5 Tasks FROM dual UNION ALL SELECT 'EMP 01' EmployeeID, 'PID 01' ProjectID, 1 Tasks FROM dual UNION ALL SELECT 'EMP 01' EmployeeID, 'PID 02' ProjectID, 8 Tasks FROM dual UNION ALL SELECT 'EMP 01' EmployeeID, 'PID 03' ProjectID, 9 Tasks FROM dual UNION ALL SELECT 'EMP 02' EmployeeID, 'PID 01' ProjectID, 7 Tasks FROM dual UNION ALL SELECT 'EMP 02' EmployeeID, 'PID 02' ProjectID, 4 Tasks FROM dual UNION ALL SELECT 'EMP 02' EmployeeID, 'PID 02' ProjectID, 3 Tasks FROM dual UNION ALL SELECT 'EMP 03' EmployeeID, 'PID 04' ProjectID, 1 Tasks FROM dual UNION ALL SELECT 'EMP 04' EmployeeID, 'PID 04' ProjectID, 8 Tasks FROM dual UNION ALL SELECT 'EMP 04' EmployeeID, 'PID 04' ProjectID, 7 Tasks FROM dual) SELECT EmployeeID, ProjectID, SUM(Tasks) OVER (PARTITION BY EmployeeID) EmpTasks, SUM(Tasks) OVER (PARTITION BY EmployeeID, ProjectID) ProjectTasks FROM t
Maybe you are looking for
-
cwimaq vs imaqdx image data structure
I'm using VB.net (2005) in a simple firewire camera snap and save the application. I used before CWIMAQ com objects in VB6 without problem (using the WriteImage function). I made a vast machine vision work in VB6 with the CWIMAQ, so I know that tho
-
Windows Vista BasicComputer laptop bluescreens on startup with the code 0x0000c1f5.Laptop does not completely start using installation CD.Downloaded a patch to fix this problem, but can use it because the computer will not start.
-
Have scanned, copied & printed on the machine for a couple of years, but last night in the pouring rain, water dripping from the ceiling on the top of the Cabinet where the printer is sitting. Water seemed to have gotten in the printer but the color
-
I get this error when I download... Under XP...
-
Cannot install Java error: 1606.
Original title: WHY isn't there a NO ONE CAN FIND a SOLUTION TO the error code 1606 JAVA summer goes forever, I tried everything, no point. and I see his current summer since at least 2009... What do I do make sure that I don't get window next time..