How to divide the Recordset by groups in SQL itself.
Hi, I use 10.2.4.0 Oracle.I have only one requirement, to whom I have to divide the recordset in some groups, so that they can be executed in part, but not in a single pass.
So, in the 'SELECT' clause itself I want to asssign special value (can be 1) to 50000 first then saves another value (maybe 2) to 10000 next, like wise. And yet once the total number of records will also be successive varry, if the total number of recordset is less than 10,000, then it should only affect '1' to all records. I'll put the values of the Group (1,2,3...) as another column itself.
Can you please let me know if this can be done in SQL without going for PLSQL?
Hello
This is called a Query of paging , and here's a way to do it:
WITH got_grp AS
(
SELECT x.*
, CEIL ( ROW_NUMBER () OVER (ORDER BY x_id)
/ 50000
) AS grp
FROM table_x x
-- WHERE ... -- If you need any filtering, put it here
)
SELECT * -- Or list the columns you want
FROM got_grp
WHERE grp = 1
;
ROW_NUMBER () OVER (ORDER BY x_id) assigns unique integers 1, 2, 3,... to all of all lines, in the same order as x_id (even if x_id is not unique).
CEIL (ROW_NUMBER () OVER (ORDER BY x_id) / 50000) maps the 1st 50,000 of these numbers to 1, the 2nd 50 000 votes against 2 and so on.
Calculated analytical (like ROW_NUMBER) as functions after the WHERE clause is applied, so to use the results in a WHERE clause, then you need calculate their in a subquery. If you want to just display the number and not use in a WHERE clause, so you need not a subquery.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
In the case of a DML (UPDATE), for example, the sample data should show what looks like the tables before the DML, and the results will be the content of the or the tables changed after the DML.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
See the FAQ forum {message identifier: = 9360002}
Tags: Database
Similar Questions
-
How to rename the temporary tablespace group name
How to rename the temporary tablespace group name? I have to remove all the temporary tablespace under the Group and then re-create the temporary tablespace again.
EBS r12.1.1
Database 11.0.1.7
Please see any id doc.
concerning
pritesh Rodriguez
Thanks for your update. I have solved my problem by creating a new group and add temporary tablespace to new goup.
concerning
pritesh Rodriguez
-
Hi all...
Here, I use the following scripts...
create table a10 (eno number, date f, date t, number of sal)
INSERT IN A10 (ENO, F, T, SAL) VALUES)
1, TO_Date (1 July 2013 12:00:00 AM ',' DD/MM/YYYY HH: mi: SS AM'), TO_Date (June 30, 2014 12:00 ',' DD/MM/YYYY HH: mi: SS AM')
(100);
INSERT IN A10 (ENO, F, T, SAL) VALUES)
1, TO_Date (May 1, 2013 12:00:00 AM ',' DD/MM/YYYY HH: mi: SS AM'), TO_Date (April 30, 2014 12:00 ',' DD/MM/YYYY HH: mi: SS AM')
(200);
COMMIT;
entry:
ENO F T SAL
07/01/2013 2014/06/30 100 1
1 05/01/2013 30/04/2014 200
Expected results:
ENO F T SAL 1 05/01/2013 2013/06/30 200
1 30/04/2014 300 07/01/2013
1 05/01/2014 2014/06/30 100
I'm little bit confused how to divide the dates here... Any help is appreciated.
Thank you all
Stéphane
Hello
Always tell what version of Oracle you are using, especially if it's so old.
In Oracle 10 (or 9, by the way) you can do this way:
WITH cntr AS
(
SELECT LEVEL AS n
OF the double
CONNECT BY LEVEL<=>=>
)
got_change_date AS
(
SELECT d.eno
C.n
WHEN 1 THEN f
ANOTHER t + 1
END AS change_date
C.n
WHEN 1 THEN 1
OF ANOTHER-1
END as mul
sal
BY a10 d
CROSS JOIN cntr c
-WHERE... - If you need any filtering, put it here
)
got_total_sal AS
(
SELECT eno
change_date f
Advance (change_date) OVER (PARTITION BY eno
ORDER BY change_date
) - 1 AS t
SUM (sal * mul) over (PARTITION BY eno
ORDER BY change_date
) AS total_sal
OF got_change_date
)
SELECT *.
OF got_total_sal
WHERE t IS NOT NULL
ORDER BY eno, f
;
-
How to divide the column Date OBIEE
Hello
We have the name of the date column: To_Date and the format is DD/MM/YY hh.
How to divide the date in YEARS, MONTHS, DAY as new columns.
kindly help on that.
Kind regards.
CHR
Published by: 867932 on November 23, 2011 22:18Hi user,
All 3 functions can be written in RPD too. MDB layer, duplicate the date column-> the mapping tab to column of Goto-> expression-> functions Builder Select-> calendar Date functions / hour-> select DayofMOnth function. The column of your logic formula will look like,
DayofMonth (YourDateColumn)
Rgds,
DpKa -
How to solve the error ORA-00001 in SQL Insert?
Hi all, I need your help appreciated.
I do a plsql procedure that inserts a line according to the value of the slider, I have error oracle ORA-00001: unique constraint (constraint_name) violated.
This message may appear if a duplicate entry exists at a different level: in the RDBMS MySQL, I have the syntax IGNORES to solve this error of duplication... and in Oracle?
Thanks for your time and your advice.
Miguelitouser6317803 wrote:
How to solve the error ORA-00001 in SQL Insert?ORA-00001 means table a unique/primary key / index and you attempt to insert a row with the key value already exists in the table. I'll assume table has a primary key on COUNTRY_ID. Then modify SQL for:
SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID ="BZ").
There is a good chance COUNTRY table also has unique key/index on COUNTRY_NAME. If so use:
SQL = "INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) SELECT"BZ","BLZ", 3 DOUBLE WHERE DOES NOT EXIST (SELECT 1 FROM COUNTRIES WHERE COUNTRY_ID = 'BZ' OR 'BLZ' = COUNTRY_NAME).
SY.
-
How to divide the three PARTITION HD
I bought the new PC HP 1350EJ G6
and
I would like to divide the PARTITION HD 3: Application of the system, Document,
Please how can I do?
Thanks much AVI kl
{Information}
Going to be hard to do since you already have 4 primary partitions. See the link below
-
How to divide the Panel layer in two?
How do divide you the layers panel in half? I've seen references to do this but Googling this question does not work.
I use CS2
Far as I can tell that the person referred to the screenshot of the layers panel appeared in the article, not the real layers panel in Photoshop.
-
I'm having the same problem as user "Gabe the facilitator" in a message sent in 2007.
«My recordset that animates a PivotTable will not filter the results based on a session variable.» I know that the session variables are working because I have the echo of session variable in the page (dragged-n-dropped my session variable since the panels on my page links), and that works fine. So why can't filter my recordset with the same session variable? »
Here is the code:
<? php require_once('Connections/mockconn.php');? >
<? PHP
session_start();
? >
<? PHP
If (! function_exists ("GetSQLValueString")) {}
function GetSQLValueString ($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
If (via PHP_VERSION < 6) {}
$theValue = get_magic_quotes_gpc()? stripslashes ($TheValue): $theValue;
}
$theValue = function_exists ("mysql_real_escape_string")? mysql_real_escape_string ($TheValue): mysql_escape_string ($theValue);
Switch ($theType) {}
case 'text ':
$theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";
break;
case "long":
case "int":
$theValue = ($theValue! = "")? intval ($TheValue): 'NULL ';
break;
case "double":
$theValue = ($theValue! = "")? doubleVal ($TheValue): 'NULL ';
break;
case "date":
$theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";
break;
case "set":
$theValue = ($theValue! = "")? $theDefinedValue: $theNotDefinedValue;
break;
}
Return $theValue;
}
}
{if (! session_id ())}
session_start();
}
$colname_info = "-1";
If (isset($_SESSION['email'])) {}
$colname_info = $_SESSION ['email'];
}
@mysql_select_db ($database_mockconn, $mockconn);
$query_info = sprintf ("SELECT name, last_name, email, password registration E-mail WHERE = %s", GetSQLValueString ($colname_info, "text") ");
$info = mysql_query ($query_info, $mockconn) or die (mysql_error ());
$row_info = mysql_fetch_assoc ($info);
$totalRows_info = mysql_num_rows ($info);
? >
< ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""
" < html xmlns =" http://www.w3.org/1999/xhtml ">
< head >
< meta http-equiv = "Content-Type" content = text/html"; charset = utf-8 "/ >"
Home < title > < /title >
< / head >
< body >
< div id = "info" > Hello <? PHP echo $row_info [""];? > < / div >
<? PHP
If (isset($_SESSION['email'])) {}
echo ' your email: '.' '. $_SESSION ['email'].' '.' good work ";}
? >
< / body >
< / html >
PLEASE PLEASE HELP... I've been to this day of...
How do I filter the recordset based on the value of the session variable
Then it works fine.
Each test returned correct results. We checked one) your session variable is set correctly, b) the SQL statement is properly filtered by email, and c) the returned results are as expected.
-
How to divide the resultset SQL based on the data in the form of scenarios?
Hello
I need to develop a query that should be divided into scenarios
Ex:
Scenario 1: If a product is sold to the United States and charged in the United Kingdom
Scenario 2: If a product is sold to the United Kingdom and charged in the United States
Scenario 3: If a product is sold and invoiced to the United States
Scenario 4: If a product is sold and invoiced to the United Kingdom
Based on 1 how to divide and provide SQL result to users based on the scenarios?
Ex: Result should show all the data, saying that the result set is in scenario 1, etc..,.
Please advice
Thank you
user12048986Hello
You can use an expression BOX to classify each line:
CASE sold_country || ' ' || billed_country WHEN 'US UK' THEN 1 WHEN 'UK US' THEN 2 WHEN 'US US' THEN 3 WHEN 'UK UK' THEN 4 END AS scenario_num
If sold_country or billed_country is anything except 'UK' or 'US', then the above expression returns null.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data. -
How to divide the DB results in addition to a column
I have some code (see below) which separates the results from a query db in two columns. However, the results print left to right, row by row. Which displays almost correctly, however, I need to display the results of the first half in a column, and the second half of the results in a second column. I can't understand how to change the code to display the first column with 1/2 of the results.
< CFSET maxcol = 2 >
< TABLE BORDER = "0" cellpadding = "3" cellspacing = "0" >
< CFSET outcol = 0 >
< CFOUTPUT QUERY = "Candidate" >
< CFIF outcol EQ 0 > < TR > < / CFIF >
< TD width = "30%" > < span class = "BodyContent" > #Candidate # </span > < table >
< CFSET outcol = outcol + 1 >
< CFIF outcol EQ maxcol >
< /TR >
< CFSET outcol = 0 >
< / CFIF >
< / CFOUTPUT >
< CFIF outcol NEQ 0 > < /TR > < / CFIF >This could be a little Kludgy, but hey, it works...
First of all, a quick count of the db
SELECT COUNT (*) AS CandidateCount
CandidatesThen divide the total by 2 and 1 for good luck.
Then write on the table.
#Candidate #.
-
How to divide the characters in table 1 d
I am looking for a way to divide the 'print' to a string 1-d subarray. For example instead of:
1 / AAAABBBB
2 / CCCCDDDD
3 / EEEEFFFF
...
etc.
then there would be two tables 1 d separated where before there was a:
1 / AAAA and BBBB
2 / CCCC and Delalande
3 / EEEE and FFFF
...
etc.
Something like that?
You need better on where the split to take place? I doubt somehow you want just a simple divided into a constant place.
-
How to divide the C: drive into two partitions without a third-party program?
Hello
Is there a way to divide the C: drive into two partitions C: and D: on Windows XP without a third pary program?
If anyone has an idea, please give some steps.
Thank you.
Assem
Hey Assem,
Once you have created a primary partition, it is not possible (for Windows XP) to divide the partition without using third-party software. You can see:http://support.microsoft.com/kb/309000 to create a new partition.
I hope this helps...
-
How to divide the string in bb-cascades
I have a table of data as json
{"RegistrationResult":"Registered Success:Empid:157:TableName:COMPANY156"}
Now, how I want to split the show list view in qml and string as the follwing
Success stories
EmpID = 157
TableName = COMPANY156
Please tell the concept of cutting a string and show the result in qml
I can get the result of the follwing method:
{"RegistrationResult":["Registered Success","Empid":"157","TableName":"COMPANY156"]}
But I do not know how to split the string for a first... Help, please...
svmrajesh wrote:
,......
"Registered Success:Empid:157:TableName:COMPANY156"}
Take a look at QString docu
Just do something like
myString.split(':')
and you get a QStringList and this QStringList is directly mapped to a table in QML JavaScript
-
How to divide the amount of import control program command line
Hi Experts
Divide the amount of command-line client 102000 99000 and 3000.
I used following scripts, but he just updated the quantity on the line, but do not add a new line for the remaining quantity.
1 INSERT IN oe_headers_iface_all
(
order_source_id,
orig_sys_document_ref,
org_id,
ORDER_NUMBER,
CUSTOMER_PO_NUMBER,
SOLD_TO_ORG_ID,
CLIENT_NAME,
CUSTOMER_NUMBER,
OPERATION_CODE,
created_by,
CREATION_DATE,
last_updated_by,
last_update_date,
CHANGE_SEQUENCE,
FORCE_APPLY_FLAG
)
VALUES)
0,
"LT_TEST7,"
204,
67081,
"4500007067-01',
1290
"Networks of c. a.",
'1143 ',
"UPDATE."
-1,
SYSDATE,
-1,
SYSDATE,
1,
« Y »
);
2. INSERT IN oe_lines_iface_all
(
order_source_id,
orig_sys_document_ref,
orig_sys_line_ref,
orig_sys_shipment_ref,
org_id,
ORDERED_QUANTITY,
ORDER_QUANTITY_UOM,
PRICING_QUANTITY,
PRICING_QUANTITY_UOM,
SOLD_TO_ORG_ID,
REQUEST_DATE,
INVENTORY_ITEM,
created_by,
CREATION_DATE,
last_updated_by,
last_update_date,
operation_code,
CHANGE_SEQUENCE,
CHANGE_REASON
)
VALUES)
0,
"LT_TEST7,"
"LT_TESTLINE7,"
"OE_ORDER_LINES_ALL810289.1,"
204,
99000,
"Ea."
99000,
"Ea."
1290
AUGUST 13, 2014 '.
"AS54888,"
-1,
SYSDATE,
-1,
SYSDATE,
"UPDATE."
1,
'FR '.
);
3. INSERT IN oe_lines_iface_all
(
order_source_id,
orig_sys_document_ref,
orig_sys_line_ref,
orig_sys_shipment_ref,
org_id,
ORDERED_QUANTITY,
ORDER_QUANTITY_UOM,
PRICING_QUANTITY,
PRICING_QUANTITY_UOM,
SOLD_TO_ORG_ID,
REQUEST_DATE,
INVENTORY_ITEM,
created_by,
CREATION_DATE,
last_updated_by,
last_update_date,
operation_code,
CHANGE_SEQUENCE,
SPLIT_FROM_LINE_REF,
SPLIT_FROM_SHIPMENT_REF,
CHANGE_REASON
)
VALUES)
0,
"LT_TEST7,"
"LT_TESTLINE7,"
"OE_ORDER_LINES_ALL810289.1,"
204,
3000,
"Ea."
3000,
"Ea."
1416,
"05 - SEP - 2014."
"AS54888,"
-1,
SYSDATE,
-1,
SYSDATE,
"INSERT."
1,
"LT_TESTLINE7,"
"OE_ORDER_LINES_ALL810289.1,"
'FR '.
);Any advice?
Christy
Hi all
The problem was resolved after customer compensation request_id in the header and line, thanks for your help.
Christy
-
How to assign the ID of group for each group in the SQL query.
Hi all
I want to assign the ID of group for each group (group ID of series). I tried with the row_number function but did not work for my requiredment. Here is my sample data and my requirement.
Col1 A A A A A B C D D D D E E E F G G G I want to get number of each column with ID group assign to it value. Here is my example output
Col1 County Group ID A 5 1 A 5 1 A 5 1 A 5 1 A 5 1 B 1 2 C 1 3 D 4 4 D 4 4 D 4 4 D 4 4 E 3 5 E 3 5 E 3 5 F 1 6 G 3 7 G 3 7 G 3 7 Select col1, count (1) NTC (col1 partition).
ROW_NUMBER() over (partition by col1 by col1 order) tbl_test grp_id.
Please help me solve this problem.
SELECT
COL1,
COUNT (*) ON MYCOUNT (COL1 PARTITION).
DENSE_RANK () OVER (ORDER BY COL1) GROUPID
Of
T1;
Maybe you are looking for
-
How to move photos all photos and remove iPhoto and Aperture libraries?
How can I move all the my iPhoto and Aperture photos to Photos and remove iPhoto and Aperture libraries? Photos automatically links to the old library on migration to save space with two libraries. As a related issue, there don't seem to be anyway t
-
the announcement came on a homepage before but I've never found since. I thought that was a really cool touch, but now I don't know how to retrieve
-
Installation disk - error 0xc00000e9 Startup Repair recovery image
My problem is simple. I wanted to restore to factory settings so I followed a 'how to' guide.I reboot and was pressed F8 to open the menu where the option "fix my pc. I select, a bar starts to fill and then it should open another menu with different
-
Hello I'm just wonering what someone knows how many recoveries the Pavilion 20? I vaguley remember the guy who sold it to saying me she had more than one.
-
Impossible to change the settings for the hard disk on the comments
Hi allHave a big problem.It all began this weekend when I could not save my servers vmware 1 vmware host (on 6)It shows error connection vRanger API call.After some tests I found that it is also impossible to add a Guest a new HD (on or off little ma