Distinct Value
Hi All,
I have one table having 36m record. I have below query. Need is distinct value for all 10 columns and those column are not part of Index. Query is taking long time to finish. Please help me on this.
Select Col1.Col2, col3 .....Col10 from
myTable
Group by Col1.Col2, col3 .....Col10
thanks
Deb
3360 wrote:
Frank Kulash wrote:
Hi,
3360 wrote:
Do you mean would not make it faster? As the query needs to read all of the table, a table full scan would be the fastest way to do that.Assuming there are other columns, a full index scan would be faster than a full table scan.Hi,
I assumed there were no other columns, I could be wrong though
882134 wrote:
Need is distinct value for all 10 columns
If the index contains all columns in the table (10 cols), then the index is going to be the same size (if not a bit bigger due to index overhead) and would be absolutely worthless for improving wall-clock performance of this query. Your only hope of making it faster is to use the parallel hint or 'alter session force parallel query parallel n' where in is the degree of parallelism. 36M rows really isn't that much but depending on the column datatypes and sizes, you may need quite a bit of temp space to do the 'sort distinct'.
The how often do you need to do this? Could this table benefit from an IOT (Index-Only-Table)? This assumes your WHERE clause always using at a minimum the leading columns in the index. Sounds like you could benefit from rethinking your data model.
It also assumes the index is not bigger than the table.
http://www.google.com/search?q=index+bigger+than+table
Similar Messages
-
How to get distinct values from a list and display in a ListView webpart.
Hi,
I have a requirement in which I need to pull unique/distinct values from a custom list and then display it via a listview webpart. Can any one suggest how this can be done.
If possible please share the CAMEL query to fetch distinct values from a custom list.
Thanks,
AnkitHi Ankit,
Is there any particular reason that the values need to be shown in a list view web part? Are you going to use that web part for filtering via web part connections?
I ask because the enterprise site collection features include the SharePoint List Filter web part, which may accomplish what you're looking for.
If you just need to display the values in a grid view, you might have more luck with the JavaScript Client Object Model. Try putting the following in a text file:
<style>
.CustomTableClass{display:table;table-layout:fixed}
.CustomRowClass{display:table-row;}
</style>
<div id="distinct_values_div" class="CustomTableClass">
<img src="/_layouts/loading.gif" />
</div>
<script language="JavaScript" type="text/JavaScript">
var siteUrl = '/sitecollection/web'; //use the actual subsite URL here
var listName = 'mylist'; // use the actual list name here
var field = "Title" // use the actual field you want to display here
var divToUpdate = document.getElementById("distinct_values_div");
var rowClass = "CustomRowClass";
ExecuteOrDelayUntilScriptLoaded(function(){
var clientContext = new SP.ClientContext(siteUrl);
var web = clientContext.get_web();
var lists = web.get_lists();
var list = lists.getByTitle(listName);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query></Query><RowLimit>500</RowLimit></View>');
this.collListItem = list.getItems(camlQuery);
clientContext.load(collListItem,"Include ("+field+")");
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed));
},"sp.js");
function onQueryFailed(sender, args){
divToUpdate.innerHTML = 'Unable to retrieve values: '+args.get_message());
function onQuerySucceeded(sender, args){
var allValues = [];
var listItemEnumerator = collListItem.getEnumerator();
divToUpdate.innerHTML = "";
while(listItemEnumerator.moveNext()){
var listItem = listItemEnumerator.get_current();
if(!containsString(allValues,listItem.get_item(field)){
var value = listItem.get_item(field);
allValues.push(value);
var newDiv = document.createElement("div");
newDiv.className = rowClass;
newDiv.innerHTML = value;
divToUpdate.appendChild(newDiv);
function containsString(strArray, text){
var contains = false;
for (var i=0; i<strArray.length; i++){
if(strArray[i]==text){contains = true; break;}
return contains;
</script>
Upload the text file to a library on the site, then add a content editor web part to a page where you want the distinct values to appear. In the content editor web part's properties, edit the Content Link so that it links directly to the text file. This
will cause the JavaScript to run on the page. -
Get distinct values from a coma seperated string variable
Hi ,
I am getting an comma seperated string as in parameter, now i want to get the distinct values from that string and will use those values to pass it to a query.
any helptry this:
sorry about the messiness - it's just quickly copied from some badly formatted code....
TYPE T_FieldArray IS TABLE OF varchar2(255) INDEX BY BINARY_INTEGER;
function SPLIT_CSV_FIELDS (
p_Input_Str in varchar2,
p_Delimiter in varchar2,
p_Quote_Char in varchar2)
return t_fieldarray is
v_FieldArray T_FieldArray;
v_input_str varchar2(4000);
v_field_str varchar2(255);
v_pos number;
e number := 0;
v_delim_str varchar2(3);
cur_pos number;
begin
loop
-- find each delimiter char in string
v_pos := INSTR(v_input_str, p_Delimiter);
-- each time delimiter char is found
if v_pos > 0 then
-- current field value is current string to position prior to delimiter char
v_field_str := UPPER(SUBSTR(v_input_str, 1, v_pos - 1));
-- remove quote char from end of field (if any)
v_field_str := TRIM(TRANSLATE(v_field_str, NVL(p_Quote_Char, p_Delimiter), ' '));
-- increment element number
e := e + 1;
-- get remainder of input string to check
v_input_str := SUBSTR(v_input_str, v_pos + 1, LENGTH(v_input_str) - v_pos);
v_FieldArray(e) := v_field_str;
else
-- increment element number
e := e + 1;
-- last field value is what's left of input string less quote char (if any)
v_field_str := TRIM(TRANSLATE(UPPER(v_input_str), NVL(p_Quote_Char, p_Delimiter), ' '));
v_FieldArray(e) := v_field_str;
exit;
end if;
end loop;
return v_FieldArray;
end; -
"How to get distinct values of sharepoint column using SSRS"
Hi,
I have integrated sharepoint list data to SQL Server reporting services. I am using the below to query sharepoint list data using sql reporting services.
<Query>
<SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems">
<Parameters>
<Parameter Name="listName">
<DefaultValue>{GUID of list}</DefaultValue>
</Parameter>
<Parameter Name="viewName">
<DefaultValue>{GUID of listview}</DefaultValue>
</Parameter>
<Parameter Name="rowLimit">
<DefaultValue>9999</DefaultValue>
</Parameter>
</Parameters>
</Method>
<ElementPath IgnoreNamespaces="True">*</ElementPath>
</Query>
By using this query, I am getting a dataset which includes all the columns of sharepoint list. Among these columns, I wanted to display only 2 columns (i.e Region and Sales type) using chart. I have created a Region parameter but when I click preview, the drop down box is giving me all the repeatative values of region like RG1,RG1,RG1,RG2,RG2,RG2,RG2,RG3.......... I wanted to display only distinct values of Region parameter so that whenever end user select region from the parameter drop down, it will display the respective value of Sales type column.
Also when I select only RG1 parameter, it is giving me a chart including the sales type of all the Regions. (it should display me only the sales type of RG1) How can I link these 2 columns so that they will display the values respectively.
I would really appreciate if anyone can help me out with this.
Thanks,
Sam.Hi Sam,
By code, the CAML language doesn’t have any reserved word (or tag) to set this particular filter to remove duplicate results.
In this case, we could use the custom code to get distinct records.
Here are the detailed steps:
1. Create a hidden parameter that gets all the records in one field.
Note: Please create another dataset that is same of the main dataset. This dataset is used for the parameter.
2. Create a function that used to remove the duplicate records.
Here is the code:
Public Shared Function RemoveDups(ByVal items As String) As String
Dim noDups As New System.Collections.ArrayList()
Dim SpStr
SpStr = Split(items ,",")
For i As Integer=0 To Ubound(Spstr)
If Not noDups.Contains(SpStr(i).Trim()) Then
noDups.Add(SpStr(i).Trim())
End If
Next
Dim uniqueItems As String() = New String(noDups.Count-1){}
noDups.CopyTo(uniqueItems)
Return String.Join(",", uniqueItems)
End Function
3. Create another parameter that will be used for filtering the maindata.
Please set the available value to be =Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",")
And the default value to be the value you what such as the first value:
=Split(Code.RemoveDups(JOIN(Parameters!ISSUE_STATUS_TEMP.Value, ",")), ",").(0)
4. Go to the main dataset. Open the property window of this dataset.
5. In the “Filters” tab, set the filter to be:
Expression: <The field to be filter>
Operator: =
Value: =Parameters!Region.Value
The parameter “Region” should be the parameter we created in the step3.
Now, we should get distinct values of SharePoint columns.
If there is anything unclear, please feel free to ask.
Thanks,
Jin
Jin Chen - MSFT -
Get distinct values from plsql array
Hi,
I have declared a variable as below in plsql proc.
type t_itemid is table of varchar2(10);
inserted set of items in to this using a program
now i want distinct values from that array how can i get it.I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
SQL> r
1 declare
2 type t_type is table of varchar2(10);
3 v_type t_type;
4 begin
5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
6 for i in (select column_value from table(v_type)) loop
7 dbms_output.put_line(i.column_value);
8 end loop;
9* end;
for i in (select column_value from table(v_type)) loop
ERROR at line 6:
ORA-06550: line 6, column 41:
PLS-00642: local collection types not allowed in SQL statements
ORA-06550: line 6, column 35:
PL/SQL: ORA-22905: cannot access rows from a non-nested table item
ORA-06550: line 6, column 10:
PL/SQL: SQL Statement ignored
ORA-06550: line 7, column 22:
PLS-00364: loop index variable 'I' use is invalid
ORA-06550: line 7, column 1:
PL/SQL: Statement ignored -
CE function to get distinct values from Column table
Hi All,
Could you please let me know the appropriate CE function to get the distinct values from column table.
IT_WORK = SELECT DISTINCT AUFNR FROM :IT_WO_DETAILS;
Thank you.Hi,
If you have 10g, you can use Model( with model performance is better than connect by )
Solution
========================================================================
WITH t AS
(SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 1234.567432, 1234.567432, 0989.726332'
txt
FROM DUAL)
SELECT DISTINCT TRIM(CHAINE)
FROM T
MODEL
RETURN UPDATED ROWS
DIMENSION BY (0 POSITION)
MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
RULES
(CHAINE[FOR POSITION FROM 1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
=========================================================================
Demo
=======================================================================
SQL> WITH t AS
2 (SELECT '0989.726332, 1234.567432, 3453.736379, 3453.736379, 0989.726332, 3453.736379, 123
4.567432, 1234.567432, 0989.726332'
3 txt
4 FROM DUAL)
5 SELECT DISTINCT TRIM(CHAINE)
6 FROM T
7 MODEL
8 RETURN UPDATED ROWS
9 DIMENSION BY (0 POSITION)
10 MEASURES (CAST( ' ' AS VARCHAR2(50)) AS CHAINE ,txt ,LENGTH(REGEXP_REPLACE(txt,'[^,]+',''))+1 NB_MOT)
11 RULES
12 (CHAINE[FOR POSITION FROM 1 TO NVL(NB_MOT[0],1) INCREMENT 1] =
13 CASE WHEN NB_MOT[0] IS NULL THEN TXT[0] ELSE REGEXP_SUBSTR(txt[0],'[^,]+',1,CV(POSITION)) END );
TRIM(CHAINE)
3453.736379
1234.567432
0989.726332
SQL>
======================================================================== -
How to get Distinct Values from Answers
Hi,
How to get Distinct values from answers, i've tried to put some functions on it.
Thanks,
MalliMalli,
Are you trying to fetch data from Dimension Attr OR Fact Measures? Did you try the advance tab - > Advanced SQL Clauses - > Check this box to issue an explicit Select Distinct. -
Distinct values from dynamic internal tabls
Hi All,
I have a dynamic internal tables like <dy_table> , i want to get distinct values from this internal tables,
how to do that, structure of dynamic internal tables is dynamic acc. to user conditions.
regards,
AnujHi Anuj
Just try this,
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = tb_fields_for_it
IMPORTING
ep_table = gp_dyn_table.
ASSIGN gp_dyn_table->* TO <gt_table>.
ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.
LOOP AT tb_output.
*To assign value for serial number.
ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.
<ls_field> = tb_output-sno.
UNASSIGN <ls_field>.
*To assign value for Sales Organization.
ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.
<ls_field> = tb_output-vkorg.
UNASSIGN <ls_field>.
*To assign Rate for its respective Condition type.
LOOP AT tb_konp WHERE knumh = tb_output-knumh.
READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.
IF sy-subrc EQ 0.
lv_count = tb_fieldcat1-col_pos.
ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.
IF tb_konp-konwa EQ '%'.
tb_konp-kbetr = tb_konp-kbetr / co_10.
<ls_field> = tb_konp-kbetr.
ELSE.
<ls_field> = tb_konp-kbetr.
ENDIF.
ENDIF.
ENDLOOP.
lv_count = lv_count + 1.
APPEND <fs_table> TO <gt_table>.
CLEAR <fs_table>.
ENDLOOP.
Hope this proves helpful to you. -
How to create a table with distinct values ?
I want to create a new table based on an existing table distinct values only, how can I avoid to create the duplicate values ?
e.g.
table1
field1 field2
0001 ABD
0001 ABD
0002 DCF
0002 DCF
new table
field1 field2
0001 ABD
0002 DCF
thankscreate table table2
as
select distinct field1,field2
from table1 -
Need of SQL query in selecting distinct values from two tables
hi,
I need a query for selecting distinct values from two tables with one condition.
for eg:
there are two tables a & b.
in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
can anybody please help me.
Thanks in advance,
RatheeshNot sure what you mean either, but perhaps this will start a dialog:
SELECT DISTINCT a.empno,
a.name,
a.sex,
b.salary,
b.doj
FROM a,
b
WHERE a.empno = b.empno;Greg -
What is '#Distinct values' in Index on dimension table
Gurus!
I have loaded my BW Quality system (master data and transaction data) with almost equivalent volume as in Production.
I am comparing the sizes of dimension and fact tables of one of the cubes in Quality and PROD.
I am taking one of the dimension tables into consideration here.
Quality:
/BIC/DCUBENAME2 Volume of records: 4,286,259
Index /BIC/ECUBENAME~050 on the E fact table /BIC/ECUBENAME for this dimension key KEY_CUBENAME2 shows #Distinct values as 4,286,259
Prod:
/BIC/DCUBENAME2 Volume of records: 5,817,463
Index /BIC/ECUBENAME~050 on the E fact table /BIC/ECUBENAME for this dimension key KEY_CUBENAME2 shows #Distinct values as 937,844
I would want to know why the distinct value is different from the dimension table count in PROD
I am getting this information from the SQL execution plan, if I click on the /BIC/ECUBENAME table in the code. This screen gives me all details about the fact table volumes, indexes etc..
The index and statistics on the cube is up to date.
Quality:
E fact table:
Table /BIC/ECUBENAME
Last statistics date 03.11.2008
Analyze Method 9,767,732 Rows
Number of rows 9,767,732
Number of blocks allocated 136,596
Number of empty blocks 0
Average space 0
Chain count 0
Average row length 95
Partitioned YES
NONUNIQUE Index /BIC/ECUBENAME~P:
Column Name #Distinct
KEY_CUBENAMEP 1
KEY_CUBENAMET 7
KEY_CUBENAMEU 1
KEY_CUBENAME1 148,647
KEY_CUBENAME2 4,286,259
KEY_CUBENAME3 6
KEY_CUBENAME4 322
KEY_CUBENAME5 1,891,706
KEY_CUBENAME6 254,668
KEY_CUBENAME7 5
KEY_CUBENAME8 9,430
KEY_CUBENAME9 122
KEY_CUBENAMEA 10
KEY_CUBENAMEB 6
KEY_CUBENAMEC 1,224
KEY_CUBENAMED 328
Prod:
Table /BIC/ECUBENAME
Last statistics date 13.11.2008
Analyze Method 1,379,086 Rows
Number of rows 13,790,860
Number of blocks allocated 187,880
Number of empty blocks 0
Average space 0
Chain count 0
Average row length 92
Partitioned YES
NONUNIQUE Index /BIC/ECUBENAME~P:
Column Name #Distinct
KEY_CUBENAMEP 1
KEY_CUBENAMET 10
KEY_CUBENAMEU 1
KEY_CUBENAME1 123,319
KEY_CUBENAME2 937,844
KEY_CUBENAME3 6
KEY_CUBENAME4 363
KEY_CUBENAME5 691,303
KEY_CUBENAME6 226,470
KEY_CUBENAME7 5
KEY_CUBENAME8 8,835
KEY_CUBENAME9 124
KEY_CUBENAMEA 14
KEY_CUBENAMEB 6
KEY_CUBENAMEC 295
KEY_CUBENAMED 381Arun,
The cube in QA and PROD are compressed. Index building and statistics are also up to date.
But I am not sure what other jobs are run by BASIS as far as this cube in production is concerned.
Is there any other Tcode/ Func Mod etc which can give information about the #distinct values of this Index or dimension table?
One basic question, As the DIM key is the primary key in the dimension table, there cant be duplicates.
So, how would the index on Ftable on this dimension table show #distinct values less than the entries in that dimension table?
Should the entries in dimension table not exactly match with the #Distinct entries shown in
Index /BIC/ECUBENAME~P on this DIM KEY? -
Hi Vlad,
I am encountering a problem with the xsl transform, if a value in the input xml is same in same/multiple orders, the unique values gets appended in the same node, in the below example, I have an order with SKU "2" with Qty "1" and SKU "4" with Qty "2", so, my csv file will come with 3 lines, 1 line for SKU "2" and 2 lines for SKU4. The output seems to append both the distinct values (like <ns0:quantity_ordered>*1 2*</ns0:quantity_ordered>) in the same node as shown in the example below. I don't know whether I am using a wrong key in the Item_Data or something else,
I believe, I am not using the right condition to check for the distinct SKU or using a wron for-each condition, I am not sure if that is the problem. I would appreciate if you could point me to the problem.
Thanks,
VenkateshHi Vlad,
That was really helpful. Thank You!
I think this one is almost done except for one particular scenario, where, an order has a duplicate of same SKU (different qty), only one SKU is displayed under Item_data node.
For example,
Order 1001 has SKU 1 with Qty of 1 and a duplicate of the same SKU with Qty as 2, In this case, only the first SKU is used and the second one with the Qty 2 gets ignored.
Order# SKU QTY
1001 1 1
1001 1 2
The input xml would be
<DailySummary>
<OrderDetails>
<PurchaseOrderNumber>1001</PurchaseOrderNumber>
<SKU>1</SKU>
<Qty>1</Qty>
<OrderDetails>
<OrderDetails>
<PurchaseOrderNumber>1001</PurchaseOrderNumber>
<SKU>1</SKU>
<Qty>2</Qty>
<OrderDetails>
<DailySummary>The expected output is,
<ns2:item_Data>
<ns0:vendor_item_number>1</ns0:vendor_item_number> (SKU)
<ns0:quantity_ordered>1</ns0:quantity_ordered> (QTY)
<ns0:quantity_shipped>1</ns0:quantity_shipped>
<ns0:unit_cost>1</ns0:unit_cost>
<ns0:extended_cost>1</ns0:extended_cost>
</ns2:item_Data>
<ns2:item_Data>
<ns0:vendor_item_number>1</ns0:vendor_item_number> (SKU)
<ns0:quantity_ordered>2</ns0:quantity_ordered> (QTY)
<ns0:quantity_shipped>2</ns0:quantity_shipped>
<ns0:unit_cost>1</ns0:unit_cost>
<ns0:extended_cost>2</ns0:extended_cost>
</ns2:item_Data>
</ns1:order>The XSL used to transform is shown below, There is a for each distinct-values for the SKU, can the 'for each' be combined to check for SKU and Qty?, so that for an order if SKU is distinct and Qty is not then take both SKU's and appropriate qty.
<xsl:for-each select="fn:distinct-values(/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo]/tns:SKU/text())">
<xsl:variable name="tmpSKU" select="."/>
<ns2:item_Data>
<ns0:vendor_item_number>
<xsl:value-of select="/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo and tns:SKU = $tmpSKU][1]/tns:SKU"/>
</ns0:vendor_item_number>
<ns0:quantity_ordered>
<xsl:value-of select="/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo and tns:SKU = $tmpSKU][1]/tns:QtyOrdered"/>
</ns0:quantity_ordered>
<ns0:quantity_shipped>
<xsl:value-of select="/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo and tns:SKU = $tmpSKU][1]/tns:QtyShipped"/>
</ns0:quantity_shipped>
<ns0:unit_cost>
<xsl:value-of select="/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo and tns:SKU = $tmpSKU][1]/tns:Price"/>
</ns0:unit_cost>
<ns0:extended_cost>
<xsl:value-of select="/tns:DailySummary/tns:OrderDetails[tns:PurchaseOrderNumber = $tmpOrdNo and tns:SKU = $tmpSKU][1]/tns:Net"/>
</ns0:extended_cost>
</ns2:item_Data>
</xsl:for-each>
I appreciate all your help,
Thanks,
Venkatesh -
I have SSRS parametarized report in that one data set have repeated values with query parameter . but while am mapping that query
parameter to report parameter i need to pass distinct values. How can i resolve thisHi nancharaiah,
If I understand correctly, you want to pass distinct values to report parameter. In Reporting Service, there are only three methods for parameter's Available Values:
None
Specify values
Get values from a query
If we utilize the third option that get values from a dataset query, then the all available values are from the returns of the dataset. So if we want to pass distinct values from a dataset, we need to make the dataset returns distinct values. The following
sample is for your reference:
Select distinct field_name from table_name
If you have any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Select records based on first n distinct values of column
I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column.
eg:
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
7 lmn 10
so on... (till some count)
Result should be
Query 1 should result --->
ID name age
1 abc 10
1 def 20
2 ghi 10
2 jkl 20
2 mno 60
3 pqr 10
query 2 should result -->
4 rst 10
4 tuv 10
5 vwx 10
6 xyz 10
6 hij 10
query 3 should result -->
7 lmn 10
9 .. ..
so on..
How to write a query for this inside a loop.Hi,
So, one group will consist of the lowest id value, the 2nd lowest and the 3rd lowest, reggardless of how many rows are involved. The next group will consist of the 4th lowest id, the 5th lowest and the 6th lowest. To do that, you need to assign numbers 1, 2, 3, 4, 5, 6, ... to the rows in order by id, with all rows having the same id getting the same number, and without skipping any numbers.
That sounds like a job for the analytic DENSE_RANK function:
WITH got_grp_id AS
SELECT id, name, age
, CEIL ( DENSE_RANK () OVER (ORDER BY id)
/ 3
) AS grp_id
FROM table_x
SELECT id, name, age
FROM got_grp_id
WHERE id = 1 -- or whatever number you want
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
See the forum FAQ {message:id=9360002} -
Oracle UCM distinct values for attribute in GET_SEARCH_RESULTS ResultSet
hi, can anyone, please, tell if there is a way to get a distinct values of resultset of GET_SEARCH_RESULTS?
I mean, is it possible to obtain distinct values with custom where values of attribute through api?
I need to build somewhat like autosuggest feature, but afaik there is no such service.
Alternatives are
- build my own service which can accept query text, pass it to GET_SEARCH_RESULTS, get results, calculate distinct and output it in hda - i dont like this idea, becouse it means getting whole result set into java while it is efficient to handle in DB
- customize CHECK_IN/UPDATE services to update cached distincts (that means no grouping on custom queries)
May be there was some sort of discussion or blog note?
Thanks in advance.If you do not declare "SearchEngineName" as part of the request, whatever value is defined in config.cfg is used. This behavior is by design.
Setting it in your request allows you to override the system setting in order to use another search engine, provided that the rest of the underlying parts are in place for the engine you are trying to use. For example, if your system setting is "DATABASE.METADATA", setting your individual request to "ORACLETEXTSEARCH" will probably fail, since the Oracle full text indexes would not exist. But if you are doing just metadata searching based on a couple of columns, and don't need the full text part for the request, it's a good way to craft a very specific search. Combined with a couple of database indexes on the columns in the where clause, it's also a good performer.
I do "SearchEngineName=DATABASE" usually in conjunction with the parameter "SearchQueryFormat=Native" so I can create some database specific queries in native SQL (and thus avoiding the need to figure out the exact internet or universal syntax.) Your mileage may vary. -
Retrieve Distinct Values using XQuery
The following query is returning me duplicate rows. How can we retrieve the distinct values? Can we use Distinct somewhere in this query? Please help me.
SELECT XMLQuery('<Update>
{ for $demo in (ora:view("TableA")),
$demo_audit in ora:view("TableA_AUDIT")
let $demo_id := $demo/ROW/ID/text(),
$demo_audit_trans_date := $demo_audit/ROW/DATE/text(),
$demo_audit_id := $demo_audit/ROW/ID/text(),
$demo_audit_type := $demo_audit/ROW/TYPE/text()
where $demo_id = $demo_audit_id and
$demo_audit_type = "U"
return
<result>
<type>U</type>
<id>{$demo_id}</id>
</result>}</Data>' RETURNING CONTENT)
FROM dual;Geoff,
I tried distinct-values in both let and return; however the result isn't distinct. Is the usage correct?
SELECT XMLQuery('<Update>
{for $a in ora:view("EMP")
let $a_empno := distinct-values($a/ROW/EMPNO/text()),
$a_ename := $a/ROW/ENAME/text(),
$a_job := $a/ROW/JOB/text(),
$a_mgr := $a/ROW/MGR/text(),
$a_deptno := distinct-values($a/ROW/DEPTNO/text())
return
<op>
<empno>{distinct-values($a_empno)}</empno>
<name>{$a_ename}</name>
<deptno>{distinct-values($a_deptno)}</deptno>
</op>}
</Update>'
RETURNING CONTENT)
FROM dual;
The output generated is given below:
<Update>
<op>
<empno>1</empno>
<name>Henry</name>
<deptno>10</deptno>
</op>
<op>
<empno>1</empno>
<name>Henry1</name>
<deptno>10</deptno>
</op>
</Update>
Maybe you are looking for
-
Customer payment(f-28)
dear sap gurus, i am a sap sd consl, but one of my fi user is having a problem recieving the payt (f-28) that he wants bill number to be knocked off against which he is recieving the payment. because we are a automotive oem suppliers ,ou customers pa
-
Payment Advice errors ( window Main )
Hi Gurus I am generating the payment advice for 2 different vendors based on their 2 different languages. CZ - language & EN ( Using the Texts in Recipients Langauge option) I am getting the following error during the payment program run with payment
-
How do I force Qt to open all vids maximized? + Ignore imbedded autoplay?
Every time I open a movie, QT opens it in the default video size, and every time I have to maximize it. I'm tired of doing that! WMP and REAL both have the ability to open all vids in maximized mode, but I can't find that option in QT. Is there any w
-
HTML & CSS editing applications
I feel this is posted in the wrong place. if it is, all apologies. I am looking for an HTML, CSS editor for my mac. I understand Adobe has Dreamweaver, which I would love, but I am trying to be cheap. I currently use pixelmator rather than photoshop
-
Problem in trying to uninstall firefox 5
I am trying to uninstall Firefox 5. I am using a desktop with XP Pro. Nothing happens when I go to the contol panel and uninstall. I click on remove and nothing happens. I also went to C:\program files\mozillafirefox\uninstall but their is no helper.