Group values by Max + equal values
Hi Experts,I'm looking for a query where I can group data accordingly and exclude the lines that didn't need.please helps to achieve this.
I have data like this in my picture
Number of type Cust_id
ABC 10 19
10 19 abcde
10 8 abcde
20 e 8
20 4 u
f 30 30
I need to put like this
Number of type Cust_id
ABC 10 19
10 19 abcde
20 e 8
f 30 30
Thank you
Bharat
Look at my first post:
Re: Group values by Max + equal values
Tags: Database
Similar Questions
-
Needing a maximum date using the group value of
I need a join_date of date value maximum for each Department. If max (join_date) has two records for each dept max (end_date) are to be considered. I used a select queryCreate table student (dept number(10), dep_name varchar2(10),join_date date,years_attended number(10),end_date date); insert into student values (1,'I',to_date('3/7/1917','MM/DD/YYYY'),4,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (1,'I',to_date('1/1/1900','MM/DD/YYYY'),4,to_date('8/26/1932','MM/DD/YYYY')); insert into student values (1,'D',to_date('1/1/1920','MM/DD/YYYY'),5,to_date('8/26/1994','MM/DD/YYYY')); insert into student values (1,'C',to_date('1/1/1920','MM/DD/YYYY'),6,to_date('8/26/1945','MM/DD/YYYY')); insert into student values (2,'I',to_date('7/1/1900','MM/DD/YYYY'),3,to_date('8/26/1932','MM/DD/YYYY')); insert into student values (2,'I',to_date('8/16/1916','MM/DD/YYYY'),9,to_date('8/26/1923','MM/DD/YYYY')); insert into student values (2,'D',to_date('8/16/1916','MM/DD/YYYY'),10,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (3,'I',to_date('3/7/1917','MM/DD/YYYY'),4,to_date('8/26/1987','MM/DD/YYYY')); insert into student values (3,'D',to_date('7/28/1920','MM/DD/YYYY'),6,to_date('8/26/1945','MM/DD/YYYY')); insert into student values (3,'I',to_date('7/28/1920','MM/DD/YYYY'),8,to_date('8/26/1965','MM/DD/YYYY')); insert into student values (4,'I',to_date('12/31/1924','MM/DD/YYYY'),2,to_date('8/26/1998','MM/DD/YYYY')); insert into student values (4,'I',to_date('6/10/1929','MM/DD/YYYY'),1,to_date('8/26/1943','MM/DD/YYYY')); insert into student values (4,'C',to_date('1/17/1927','MM/DD/YYYY'),4,to_date('8/26/1955','MM/DD/YYYY')); insert into student values (4,'C',to_date('6/10/1929','MM/DD/YYYY'),30,to_date('8/26/1967','MM/DD/YYYY')); insert into student values (5,'D',to_date('2/10/1931','MM/DD/YYYY'),2,to_date('8/26/1943','MM/DD/YYYY')); insert into student values (5,'I',to_date('2/10/1931','MM/DD/YYYY'),24,to_date('8/26/1962','MM/DD/YYYY')); commit;
gives me the following resultselect * from student where join_date in (select max(join_date) from student group by dept);
But I'm looking for the result that gives me only a maximum value for each column dept. First of all, it should look like to a maximum value of join_date, so two records even join_date max (end_date) are to be considered. The result should be sumthing like this1 D 1/1/1920 5 8/26/1994 1 C 1/1/1920 6 8/26/1945 2 I 8/16/1916 9 8/26/1923 2 D 8/16/1916 10 8/26/1987 3 D 7/28/1920 6 8/26/1945 3 I 7/28/1920 8 8/26/1965 4 I 6/10/1929 1 8/26/1943 4 C 6/10/1929 30 8/26/1967 5 D 2/10/1931 2 8/26/1943 5 I 2/10/1931 24 8/26/1962
Can you please tell me how to rewrite the select query for results above.1 D 1/1/1920 5 8/26/1994 2 D 8/16/1916 10 8/26/1987 3 I 7/28/1920 8 8/26/1965 4 C 6/10/1929 30 8/26/1967 5 I 2/10/1931 24 8/26/1962
Published by: user11872870 on August 2, 2011 17:29
Published by: user11872870 on August 2, 2011 17:36Hello
This is called a Query Top - N , and this is a way to do it:
WITH got_r_num AS ( SELECT student.* , ROW_NUMBER () OVER ( PARTITION BY dept ORDER BY join_date DESC , end_date DESC ) AS r_num FROM student ) SELECT dept, dep_name, join_date, years_attended, end_date FROM got_r_num WHERE r_num = 1 ORDER BY dept ;
Another way is similar to what you posted:
SELECT * FROM student WHERE (dept, join_date, end_date) IN ( SELECT dept , MAX (join_date) , MAX (end_date) KEEP (DENSE_RANK LAST ORDER BY join_date) FROM student GROUP BY dept );
I suspect that the first way (using ROW_NUMBER) will be faster.
In addition, the ROW_NUMBER approach is guaranteed to return only 1 line by Department using the approach of GROUP BY, if there is a link on join_date and end_date then it will return all the contenders in this Department. using ROW_NUMBER, it is easy to add expressions to tie-break as much as you want, and, if there is still a tie, it will be arbirarily pick, one lines involved in the tie as #1.Thanks for posting the CREATE TABLE and INSERT! It is very useful.
Published by: Frank Kulash, August 2, 2011 21:00
Added GROUP BY alternative -
SQL: Rearrange random a column within a grouping value
10g release 2.
I have a grouping column and a column of data.
I am looking for a SELECT statement that will pull all the x 1 for a random ID given, such that every x 1 original is represented once in the new random column, but this data is not "Cross" his original group ID border.CREATE TABLE t1 ( id NUMBER , x1 VARCHAR2(10) ); INSERT INTO t1 (id, x1) VALUES (1,'A'); INSERT INTO t1 (id, x1) VALUES (1,'B'); INSERT INTO t1 (id, x1) VALUES (1,'C'); INSERT INTO t1 (id, x1) VALUES (1,'D'); INSERT INTO t1 (id, x1) VALUES (1,'E'); INSERT INTO t1 (id, x1) VALUES (2,'F'); INSERT INTO t1 (id, x1) VALUES (2,'G'); INSERT INTO t1 (id, x1) VALUES (2,'H'); INSERT INTO t1 (id, x1) VALUES (2,'I'); INSERT INTO t1 (id, x1) VALUES (3,'J'); INSERT INTO t1 (id, x1) VALUES (4,'K'); INSERT INTO t1 (id, x1) VALUES (4,'L');
So, this might be valid outputs:
.. .as would have this:ID X1 RANDOMIZED ---------- ---------- ---------- 1 A E 1 B A 1 C C 1 D B 1 E D 2 F F 2 G H 2 H G 2 I I 3 J J 4 K K 4 L L
Note how the random value never cross a line ID.ID X1 RANDOMIZED ---------- ---------- ---------- 1 A A 1 B C 1 C E 1 D D 1 E B 2 F I 2 G H 2 H G 2 I F 3 J J 4 K L 4 L K
On the other hand, the following would not be outputs valid...
because randomized 'I' is now the fifth data element to group the ID 1, whereas in the table, 'I' belongs to the group ID 2. Similarly, the randomized study "D" now appears as a line associated with the ID 2, whereas it is defined initially as belonging to ID 1.ID X1 RANDOMIZED ---------- ---------- ---------- 1 A B 1 B E 1 C C 1 D A 1 E I 2 F D 2 G G 2 H F 2 I H 3 J J 4 K K 4 L L
A solution purely SQL is possible?
Thank you.Hello
It is a different and much more interesting problem!
At the heart of the solution is always good: use two different schemes of numbering (at least one of them, based on a random number) to tell which element will be substituted for each.
Here's one way:
WITH unpivoted_data AS ( SELECT id , address_ln_1 AS address_txt , 1 AS address_ln_num , 1 + LENGTH (address_ln_1) - LENGTH (REPLACE (address_ln_1, ' ')) AS token_cnt FROM t_addr UNION ALL SELECT id , address_ln_2 AS address_txt , 2 AS address_ln_num , 1 + LENGTH (address_ln_2) - LENGTH (REPLACE (address_ln_2, ' ')) AS token_cnt FROM t_addr ) , cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 1 + ( SELECT MAX (token_cnt) FROM unpivoted_data ) ) , got_tokens AS ( SELECT u.* , c.n AS token_num , REGEXP_SUBSTR ( u.address_txt , '[^ ]+' , 1 , c.n ) AS token_txt , ROW_NUMBER () OVER ( PARTITION BY u.address_ln_num , c.n ORDER BY dbms_random.string ('P', 10) ) AS o_num , ROW_NUMBER () OVER ( PARTITION BY u.address_ln_num , c.n ORDER BY dbms_random.value ) AS r_num FROM unpivoted_data u JOIN cntr c ON c.n <= u.token_cnt ) , got_scrambled_txt AS ( SELECT CONNECT_BY_ROOT id AS id , address_ln_num , TRIM ( SYS_CONNECT_BY_PATH ( token_txt , ' ' ) ) AS scrambled_txt , r_num FROM got_tokens WHERE CONNECT_BY_ISLEAF = 1 START WITH token_num = 1 CONNECT BY token_num = PRIOR token_num + 1 AND address_ln_num = PRIOR address_ln_num AND r_num = PRIOR r_num ) SELECT o.id , MIN (CASE WHEN r.address_ln_num = 1 THEN r.scrambled_txt END) AS scrambled_ln_1 , MIN (CASE WHEN r.address_ln_num = 2 THEN r.scrambled_txt END) AS scrambled_ln_2 FROM got_scrambled_txt r JOIN got_tokens o ON r.r_num = o.o_num WHERE o.address_ln_num = 1 AND o.token_num = 1 GROUP BY o.id ORDER BY o.id ;
This assumes that address_ln_1 is not NULL.
Exit (1st time):
. ID SCRAMBLED_LN_1 SCRAMBLED_LN_2 ---- ------------------------------ ------------------------------ 101 901 ORACLE PKWY 102 1 INFINITE ROAD APT 3B 103 500 ANTONIO LOOP SUITE 100
Output (2nd time: no changes to the query or table):
. ID SCRAMBLED_LN_1 SCRAMBLED_LN_2 ---- ------------------------------ ------------------------------ 101 1 ANTONIO PKWY APT 3B 102 500 INFINITE ROAD 103 901 ORACLE LOOP SUITE 100
-
Above-report of the Group-new page for every group value.
Hello
In schema Scott, I created a simple report with group above. The taskforce is Deptno.
Query is - Select * from emp.
More-> Deptno field group.
Created deposit of the total salary for deptno.
report is running. Now, my need is. for each new deptno - need to create the new page. A Department can have a page or several pages as well.
If empno repeating frame, "Page break Apres-oui...--> the employees of the Department list is ok, but the total field is printing on the next page.
But I want to employees of the Department and total salary should appear on the same page.
How to do this, please
No it's not true.
Framework repeting DEPTNO value (for example. R_G_DEPTNO) property of the print Direction through'.
I hope this works...
Hamid
-
Exclusion group values export not worksheet "merge data."
Hello world
I noticed that most of my radio button values are not displayed on the worksheet (and yet some do inexplicable). Has anyone else encountered this problem?
For anyone else struggling with this, here's how I went wrong:
I named the individual radio buttons on the palette of the hierarchy. For reasons unknown to me, let them as "(case d'option sans titre)". " I had designated names such as 'yes', 'no', and meets a few multiple choice questions. RawValues export only for these if we let them with their default unititled name. The Group of the exclusion itself can be renamed of course - who seems to have no effect on the question.
Just an example of some disconcerting shows in LiveCycle.
-
mathematical functions on radio group values
I have a form with 8 groups of radio. Each group has 6 options, each with a value between 0-6.
I need to preform the following after a selection has been made on each group.
[Sum of all selected reports / (# of sections with a selected statement x 5)] x 100
and I want the number that results should appear in a box at the bottom of the page.
Please, any help would be nice!
Here's a sample of what I think you want... .the code is located on the calculation of the Total field at the bottom.
Paul
-
HelloWe use OBIEE11g.I have report as County, Count (Ref_No)
For example
Country Volume CN 1 518 HK 161 IN 60 GB 54 BR 27 OF 23 RU 16 BD 12 VN 9 AA 5 BB 10 CC 10 DD 8 EA 20 FF 2 GG 1 How can I reach below Formate (I hsould display only 10 lines, after 9 th best values should be other County)
Country Volume CN 1 518 HK 161 IN 60 GB 54 BR 27 OF 23 RU 16 BD 12 VN 9 Others 73 Thank you
Gram
Hello
Could you open the dialogue formula column edit to the 'Other countries' column and the value of the box "treat as an attribute column? If your view of pivot should be like
Lines: Other countries
Measures: Volume
Exclude the column: country.
Diakité
-
Hi all
I have a group of radio buttons
RADIO_SUMM_DET
and 2 radio buttons in the Group
1 SUMMARY
2 DETAIL
I have 3 blocks
1 CONTROL
2 SUMMARY
3 RETAIL
I put the default RADIO_SUMM_DET 'Detail '.
I have my radio on the block of control buttons
When a new instance of the form opens
by default, the selected option button is 'DETAIL '.
When I change the option to 'SUMMARY' button and click on the search button (depending on the selected radio button, the button has the code to go to the respective block and query the records on the block) on the control block
my control goes to the block summary and displays the corresponding items in this
After having dealt with the cases I press search
in this case the control goes back to the control block
but the selected radio button is "DETAIL."
I want the 'Summary' button to be selected when I return to the control block after goingfrom the summary block
I hope you understand my problem
Thank you
Edited by: abcdxyz November 18, 2010 21:06Move the two lines in your code:
. . . :control.RADIO_DET_SUMM :='SUMMARY'; Clear_Block(No_Validate); ELSIF ... . .
TO
Clear_Block(No_Validate); :control.RADIO_DET_SUMM :='SUMMARY'; ELSIF .. . .
You navigate to the drive and then block by setting the radio to the contents and then clear the block that erases the block around, including the radio to the Group and it allows you to return without detail.
-
Hello world
Run the following query:Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi PL/SQL Release 10.2.0.3.0 - Production CORE 10.2.0.3.0 Production
I wish I had the following result, with the totals:WITH TABLE_A AS (SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_B' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_D' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_C' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_Y' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_1' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_Z' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL) SELECT ID, PRODUCT, TT_SUM, TOTAL FROM(SELECT ID, PRODUCT, COUNT(*) TT_SUM FROM TABLE_A GROUP BY ID, PRODUCT) MODEL DIMENSION BY(ID, PRODUCT) MEASURES (TT_SUM, 0 TOTAL) RULES (TOTAL[ANY, ANY] = SUM(TT_SUM) OVER (PARTITION BY ID ORDER BY PRODUCT)) ORDER BY ID, PRODUCT
How can I achieve this?ID | PRODUCT | TT_SUM | TOTAL ------------------------------- 1 | PRODUCT_A | 3 | 3 1 | PRODUCT_B | 1 | 4 1 | PRODUCT_C | 1 | 5 | PRODUCT_D | 1 | 6 | TOTAL | 6 | 18 2 | PRODUCT_1 | 1 | 1 2 | PRODUCT_2 | 2 | 3 | TOTAL | 3 | 4 3 | PRODUCT_X | 2 | 2 3 | PRODUCT_Y | 1 | 3 3 | PRODUCT_Z | 1 | 4 | TOTAL | 4 | 9
TKS in advanced,
Christian BalzThere is no need to GROUP BY:
WITH TABLE_A AS (SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_B' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_D' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_C' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_Y' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_1' PRODUCT FROM DUAL UNION ALL SELECT 1 ID, 'PRODUCT_A' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_X' PRODUCT FROM DUAL UNION ALL SELECT 3 ID, 'PRODUCT_Z' PRODUCT FROM DUAL UNION ALL SELECT 2 ID, 'PRODUCT_2' PRODUCT FROM DUAL ) SELECT ID, PRODUCT, TT_SUM, TOTAL FROM TABLE_A MODEL RETURN UPDATED ROWS DIMENSION BY(ID D1,PRODUCT D2,ROW_NUMBER() OVER(PARTITION BY ID,PRODUCT ORDER BY 1) D3) MEASURES(ID,PRODUCT,0 TT_SUM, 0 TOTAL) RULES UPSERT ALL ( TT_SUM[ANY,ANY,1] = COUNT(TT_SUM)[CV(),CV(),ANY], TOTAL[ANY,ANY,1] = SUM(TT_SUM)[CV(),D2 <= CV(),ANY], TT_SUM[ANY,NULL,1] = SUM(TT_SUM)[CV(),ANY,1], TOTAL[ANY,NULL,1] = SUM(TOTAL)[CV(),ANY,1], PRODUCT[ANY,NULL,1] = 'TOTAL' ) ORDER BY D1, D2 NULLS LAST / ID PRODUCT TT_SUM TOTAL ---------- --------- ---------- ---------- 1 PRODUCT_A 3 3 1 PRODUCT_B 1 4 1 PRODUCT_C 1 5 1 PRODUCT_D 1 6 TOTAL 6 18 2 PRODUCT_1 1 1 2 PRODUCT_2 2 3 TOTAL 3 4 3 PRODUCT_X 2 2 3 PRODUCT_Y 1 3 3 PRODUCT_Z 1 4 TOTAL 4 9 12 rows selected.
SY.
Published by: Solomon Yakobson, February 18, 2009 14:07
-
How to create a group of partially with equal fields?
I'm doing a group by the following query to the companies of the group with cnpj different although they are of the same matrix (the condition for this is that the first of the cnpj 08 numbers are equal and that the other may be different). Could you help me?
Select n.cli_nom, c.cnh_clifat, sum (c.cnh_valcnh) of cnhcad c
clicad n on n.cli_cod = c.cnh_clifat inner join
where c.cnh_datcnh between 1 January 2014 "and August 15, 2014"
and c.cnh_numcnh > 0
and c.cnh_sercnh <>"Mi".
and c.cnh_ctesta = 100
and c.cnh_clifat like 3420926% '-this would be the condition for group records
N.cli_nom group, c.cnh_clifat
sum (c.cnh_valcnh) desc order
with my_data as ( select 'company_1' company, '555874' as code, 1000.00 as billing from dual union all select 'company_2' company, '333659' as code, 500.00 as billing from dual union all select 'company_3' company, '555878' as code, 3000.00 as billing from dual union all select 'company_4' company, '333661' as code, 9000.00 as billing from dual ), transformed as ( select md.*, substr(code,1,3) code_prefix from my_data md ) select distinct t.code_prefix, sum(billing) over (partition by t.code_prefix order by t.code_prefix) billing_sum from transformed t order by t.code_prefix
CODE_PREFIX BILLING_SUM ----------- ----------- 333 9500 555 4000
-
Choose a value for max, but with restrictions?
First of all: I'm a noob-SQL...
I saw, that there is a similar question below a few threads, but it does not.
I have two tables.
1 CASE
2. STATE OF PLAY
STATUS columns:
STATUSID CASEID STATUS
1 1 01
2 1 02
3 2 01
4 3 01
5 1 03
6 2 02
7 4 01
...
Columns of CASES:
CASEID BEGINDATE
1 15/03/2014
2 07/04/2014
3 21/04/2014
4 03/05/2014
...
Now, I want to select all the cases that have the maximum status 02
Not the case who are only in status 01 and also not the case which in addition have the status 03
With:
Select caseid, max (status)
status
Caseid group;
I get max-status of all cases
With:
Select c.caseid, c.begindate, s.status
case c, s status
where c.caseid = s.caseid;
I get all the information I need, but not selected on the case with max-status
With:
Select c.caseid, c.begindate, s.status
case c, s status
where c.caseid =)
Select caseid, max (status)
status
Group caseid );
Does not work, because the subselect statement has many values...
I have no idea how to make the selection of columns with only maxstatus 01
Select caseid
status
Caseid group
After max (status) = '02';
-
can I format the values aggregated within a group
Hello everyone,
Question: How can I format the values aggregated within a group.
I created a group of - >
<? for-each - group:current-group(); / PZN? >
...
<? end for each group -? >
Inside the group, I have grouped the VALUE->
<? amount (current - group (/VALUE))? >
Now I want to format the VALUE. I tried to apply a mask to format #, # 0.00 and tried to apply
<? format - number:(sum(current-group()/PREIS));' 999G999D99'? > but either workes.
full code:
<? for-each - group:current-group(); / PZN? >
<? format - number:(sum(current-group()/PREIS));' 999G999D99'? >
<? end for each group -? >
Andybody knows what I'm doing wrong?
Thanks in advance!Sorry, I got them mixed up. This should work for you:
or
I'm not sure about your version and xslt function, but it seems that it does not recognize the xdoxslt:format_number so I guess that is not supported in the version 5.6.3.
BR
Magnus -
How to group these values by month?
Hello
I have a nice SQL statement that returns from day to day, the values of a device.
Sample values:WITH S1 AS (SELECT DATE1, ROUND(AVG(VALEUR),2) Debit FROM EVV_E032 WHERE DATE1 BETWEEN TO_DATE('01012006000000', 'DDMMYYYYHH24MISS') AND TO_DATE('31122006235959', 'DDMMYYYYHH24MISS') AND CLEF_VAR = (SELECT CLEF_VAR FROM SITE_DEBIT_RIVIERE WHERE SITE = 'E032' ) GROUP BY date1 ) SELECT NULL LINK , TO_CHAR(n, 'DD.MM'), NVL(ROUND(AVG(Debit),2), 0) "Débit" FROM (SELECT TRUNC(TRUNC(to_date(2006,'YYYY'),'year'), 'DD')-1 + level n, rownum jours FROM dual CONNECT BY level<=366 ) days LEFT JOIN s1 ON days.n = TRUNC(date1,'DD') GROUP BY n ORDER BY n
The output are grouped values from day to day. I would like to tehse group monthly values, but couldn't figure out how to do. Even if I'm not a newbie to newbie on SQL, copy the following code will much too much for me. I know that some of you guys can handle that. I tried but not sew succeed. Could you help me?Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('10/02/2006 09:49:59','DD/MM/YYYY HH24:MI:SS') 1,63); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('21/02/2006 10:35:12','DD/MM/YYYY HH24:MI:SS') 1,68); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('21/02/2006 11:30:30','DD/MM/YYYY HH24:MI:SS') 0); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('23/02/2006 14:02:02','DD/MM/YYYY HH24:MI:SS') 0); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('23/02/2006 16:22:34','DD/MM/YYYY HH24:MI:SS') 0); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('30/04/2006 18:09:08','DD/MM/YYYY HH24:MI:SS') 1,72); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('20/05/2006 11:57:02','DD/MM/YYYY HH24:MI:SS') 1,72); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('07/06/2006 15:11:58','DD/MM/YYYY HH24:MI:SS') 1,79); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('08/06/2006 20:00:26','DD/MM/YYYY HH24:MI:SS') 1,82); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('19/06/2006 09:42:32','DD/MM/YYYY HH24:MI:SS') 1,72); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('20/06/2006 04:30:00','DD/MM/YYYY HH24:MI:SS') 1,82); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('20/06/2006 10:39:01','DD/MM/YYYY HH24:MI:SS') 1,72); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('24/06/2006 19:34:50','DD/MM/YYYY HH24:MI:SS') 1,82); Insert into "EVV_E032" (DATE1,DEBIT) values (to_date('26/06/2006 14:37:26','DD/MM/YYYY HH24:MI:SS') 1,88);
Best regards, Christian.select add_months(to_date('01/01/2006', 'dd/mm/yyyy'), level - 1) n, rownum from dual connect by level <= 12; N ROWNUM --------- ---------- 01-JAN-06 1 01-FEB-06 2 01-MAR-06 3 01-APR-06 4 01-MAY-06 5 01-JUN-06 6 01-JUL-06 7 01-AUG-06 8 01-SEP-06 9 01-OCT-06 10 01-NOV-06 11 01-DEC-06 12
-
How to group the values according to the weeks of the year?
Hello
I have a table with dates and values (I'm simplifying the need for this question)
I want to group the values (and adding the) according to the 52 weeks of the year. I mean week of consolidation for the week.
Here the date of each weeks generated during a year, it gives every Monday of each week of the year:
Select trunc (trunc (sysdate, 'year'), 'iw') +(rownum*7)-7 n of object where rownum < = 53
What I want to do is to summarize the values in my table and group together them in every week, in that respect. The date of these weeks are generated by the above query.
For example all values fall into the 1st week of the year will be grouped into this date, all values fall in the 2nd wek will be grouped in this date and so on. If no value is found for a week, then a value of 0 is generated in iorder have a 52 weeks-lines. It's basically a kind of select with "date between... and...". "and group values and that affect the number of the wee, they are relevant.
Examples of Monday, June 30, 2008, 07/07/2008, 07/14/2008
Example of values and dates in my table:
Date value
30/06/08 9
07/01/08 9
07/02/08 9
07/03/08 9
07/03/08 9
07/04/08 6
07/04/08 6
07/04/08 9
07/07/08 9
07/08/08 9
29/07/08 9
29/07/08 6
30/07/08 9
07/31/08 9
07/31/08 9
07/31/08 9
08/01/08 9
08/04/08 5.5
08/04/08 9
08/07/08 9
08/07/08 9
08/08/08 9
14/08/08 9
14/08/08 9
18/08/08 9
22/08/08 9
22/08/08 9
25/08/08 9
25/08/08 9
26/08/08 9
29/08/08 9
29/08/08 9
09/01/08 9
09/01/08 9
09/04/08 9
09/04/08 9
09/05/08 9
09/05/08 9
09/05/08 9
09/05/08 9
17/09/08 9
Result should be something like this:
Number of the week Date value
47/1 12/31/2008
94/2 07/12/2008
2008-01-14 3, 23
and so on...
.....
73/52 12/22/2008
60/53 29/12/2008
I hope I am clear. Thank you for your kind replies.Something like that, maybe:
select trunc(trunc(sysdate,'year'),'iw') +((level-1)*7) n from dual connect by level<=53
(I changed it to sysdate so that the next years will take care of them!)
-
multiple function return values
Hello
create tablepermission role_
(
role_id NUMBER not null,
permission_id NUMBER not null
);
insert into role_permission (ROLE_ID, PERMISSION_ID)
values (16: 1);
insert into role_permission (ROLE_ID, PERMISSION_ID)
values (17: 1);
Insert role_permission (ROLE_ID, PERMISSION_ID)
values (18: 1);
insert into role_permission (ROLE_ID, PERMISSION_ID)
values (17: 2);
insert into role_permission(ROLE_ID, PERMISSION_ID)
values (18, 2);
insert into role_permission(ROLE_ID, PERMISSION_ID)
values (15: 1);
insert into role_permission(ROLE_ID, PERMISSION_ID)
values (20, 1);
commit;
need to create the function for a select statement to integrate it within a query.
create or replace function return_role (i number) return?
is
Start
Select role_id of
in?
(select role_id, max (y.permission_id)
of role_permission y
Role_id group
After max (y.permission_id) = 1)
end return_role;
my request should be like this:
updated roles
set = 1 ID
where role_id in (select return_role (1) double)
Please your help.
the solution should be without creating an object type in the database.
Thanks in advance
Naama
Example to demonstrate with a pipeline function (although I wouldn't recommend this way)...
SQL > create table role_permission
() 2
3 role_id NUMBER not null,
4 permission_id NUMBER not null
5 );Table created.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (16: 1);
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (17: 1).
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (18: 1);
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (17: 2);
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (18, 2);
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (15: 1);
1 line of creation.
SQL > insert into role_permission (ROLE_ID, PERMISSION_ID) values (20, 1);
1 line of creation.
SQL > commit;
Validation complete.
SQL > create type t_roles in the table of the number;
2.Type of creation.
SQL > create or replace function return_role (i number) t_roles return pipeline as
2 role of the cursor is
3. Select role_id
role_permission 4 y
Group of 5 by role_id
6. having max (y.permission_id) = 1;
7. start
8 r to the role
9 loop
hose 10 row (r.role_id);
11 end of loop;
12 end return_role;
13.The function is created.
SQL > create table roles (number role_id, identification number)
2.Table created.
SQL > insert into roles (role_id, id) values (15.0);
1 line of creation.
SQL > insert into roles (role_id, id) values (16.0);
1 line of creation.
SQL > insert into roles (role_id, id) values (17.0);
1 line of creation.
SQL > insert into roles (role_id, id) values (18.0);
1 line of creation.
SQL > insert into roles (role_id, id) values (19.0);
1 line of creation.
SQL > insert into roles (role_id, id) values (20.0);
1 line of creation.
SQL > commit;
Validation complete.
SQL > update roles
2 = 1 set ID
3 where in (select column_value role_id
table 4 (return_role (1))
5 )
6.3 lines to date.
SQL > select * from roles
2.
ROLE_ID-ID
---------- ----------
15 1
16 1
17 0
18 0
19 0
20 16 selected lines.
Maybe you are looking for
-
Satellite 1800-100: need a display driver for Win XP
Hello I downloaded the driver, trident on the Toshiba site. But when I install it, XP pro says he won't. In the .inf file I see: compatible win 95 :(Can you help or extract a good driver on the same model? I test a lot of drivers, but nothing is good
-
While loops inside while loops, how to stop?
Hey, I'm confused with a simpler question to multiple while loops. My goal: stop or pylone2, just jump out of the small loop and stay in the big one. and if I click on stop 3. the entire program would cease... How can I do this? The following script
-
I have a canon mp250 and it dosent want to print.
I lost the cd and don't know what to do
-
I didn't know you had to disable the touch screen under the water. Unit will now return but has himself put in airplane mode, and the touch screen does not work at all making them useless device. I har reset button and volume / start button combo. Do
-
BlackBerry Smartphones 1XEV - 3G
I had the storm since about 2 weeks later, he resurfaced and have yet to see him pass to the 3G. 95% of the time that it is always in 1XEV. I have not activated something or I'm constantly in a bad area?