Query Help---DISTINCT values
Hi..
I have the following query..
I'm getting the following o/p...
Offshore In-house 1858 616
Offshore In-house 1858 615
Onshore In-house 1858 611
Offshore In-house 1858 923
Offshore In-house 1858 613
Onshore In-house 1858 941
Onshore In-house 1858 940
Onshore In-house 1858 890Can I get distinct onshores and offshores values..like in the above case only one in-house for offshore and one in-house for onshore and if there are multiple repeating values for offshore and on shrore..I need only dinstinct values in both offshore and onshore..
Any help..?
Edited by: user10280715 on Apr 14, 2009 10:21 AM
If I have a result set like this..
Offshore In-house 1858 616
Offshore In-house 1858 615
Onshore In-house 1858 611
Offshore In-house 1858 923
Offshore In-house 1858 613
Onshore In-house 1858 941
Onshore In-house 1858 940
Onshore In-house 1858 890the o/p I'm looking for..
Offshore In-house 1858 616
Onshore In-house 1858 890If I have different result set like..
Offshore In-house 1858 616
Offshore In-house 1858 615
Offshore aaaaaaaa 1859 611
Offshore aaaaaaaa 1859 923
Offshore In-house 1858 613
Onshore In-house 1858 941
Onshore In-house 1858 940
Onshore eeeeeee 1860 890
Onshore eeeeeee 1860 941I'm looking for..
Offshore In-house 1858 616
Offshore aaaaaaaa 1859 611
Onshore In-house 1858 941
Onshore eeeeeee 1860 890Is it possible..
Similar Messages
-
Hi, I have this query in my 9ir2 database:
SELECT xmit.u_ii_id, xprol.ii_id
FROM xprol, ( SELECT DISTINCT u_ii_id, ii_id
FROM t
WHERE NVL(key_t,'X') <> 'P') xmit
WHERE xprol.ii_id = xmit.ii_id
AND xmit.u_ii_id <> xprol.ii_id ;
u_ii_id ii_id
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
.The query returns 12.294.938 million of rows.
I need to know de best way to filter this values... maybe using Analytic Functions?
The result of the query must be...
u_ii_id ii_id
6220 5765
7898 3409Thanks!ROW_NUMBER () OVER (PARTITION BY xmit.u_ii_id
ORDER BY xmit.u_ii_id,
xprol.ii_id) AS rn
xprol, (SELECT DISTINCT u_ii_id, ii_id
FROM t
HERE NVL (key_t, 'X') <> 'P') xmit
WHERE xprol.ii_id = xmit.ii_id AND xmit.u_ii_id <>
xprol.ii_id AND rn = 1
/code]this will not work it will give , that needs to be in subquery
ORA-00904: "RN": invalid identifier
below is just an example
SQL> select empno,e.deptno ,row_number() over(partition by deptno order by deptno) rn
2 from emp e, (select deptno from dept1
3 where deptno=10) d
4 where e.deptno=d.deptno
5 and rn=1;
and rn=1
ERROR at line 5:
ORA-00904: "RN": invalid identifier
/pre] -
Is there a more efficient way to write this query besides using DISTINCT?
I’m trying to count the number of unique account numbers by each INT.
My query works but it’s a little slow.
SELECT
act.INT
,COUNT(DISTINCT(plm.ACCT_NUMBER)) ACCT#
FROM…
GROUP BY act.INT
Any information would be greatly appreciated.
Thanks,
xPlease follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL.
And you need to read and download the PDF for:
https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
>> Is there a more efficient way to write this query besides using DISTINCT? I’m trying to count the number of unique account numbers by each INT. My query works but it’s a little slow. <<
The INT is a reserved word (INTEGER) in SQL so it should never be a column name. Using special symbols like # in a data element name is another serious ISO violation and awful programming. Use only Latin letters, digits and the minimal set of punctuation marks
from the common Unicode subset. This will let yuou use the same data element names in all the ISO standard languages zand tooils.
If you have the right indexes, the COUNT(DISTINCT <expr>) should perform fine.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Hello together,
I have the following example table:
PERSONID_____BEGINDATE_____ENDDATE_____ROOMID
1033_________1.10.2009______5.10.2009_____567
1033_________1.10.2010______5.10.2010_____891
1041_________2.11.2009______1.12.2009_____123
1041_________3.12.2010______3.12.2011_____456
What I need is the line with the highest end date by PERSONID.
In the example above I would need to see the 2nd and the 4th line.
This is the query I am using:
select example.personid, max(example.begindate), max(example.enddate), example.roomid
from example
where (example.enddate >= trunc(sysdate))
group by example.personid, example.roomid
The problem is it always gives me 4 result lines (in this example). I think because it gets grouped by the roomid, which is distinct in each line, in the example.
What I actually want is ONE result line, per person, which shows me the highest end date, independently of the room id.
Can someone please point me in the right direction? Using max(date) is correct?
Thank you very much in advance.Hi,
Welcome to the forum!
The most versatile way is:
WITH got_r_num AS
SELECT e.*
, ROW_NUMBER () OVER ( PARTITION BY personid
ORDER BY enddate DESC
) AS r_num
FROM example e
WHERE enddate >= TRUNC (SYSDATE)
SELECT * -- Or list all columns except r_num
FROM got_r_num
WHERE r_num = 1
;What do you want to do in case of a tie? For example, what if both rows for personid=1033 had the same enddate?
The query above would pick one of them arbitarily.
If you want both of them, then change ROW_NUMBER to RANK.
If you want to add a tie-breaker (e.g., pick the one with the latest begindate), then add more columns to the analytic ORDER BY clause.
Edited by: Frank Kulash on Sep 15, 2009 2:12 PM
Added <tt>WHERE enddate >= TRUNC (SYSDATE)</tt> condition -
Query help Multiple values in condition
Hi,
I am trying to do something like this
SELECT clave_grupo FROM SS_TTABLAS
WHERE CLAVE_GRUPO IN
CASE WHEN (condition) THEN 'v1'
ELSE ('v1','v2',v3')
end
This is the error msg:
ORA-00907: missing right parenthesis
just before ,'v2',v3')
Is it possible?Hi,
Welcome to the forum!
Here's one way:
SELECT clave_grupo
FROM ss_ttablas
WHERE clave_grupo = 'v1'
OR ( clave_grupo IN ('v2', 'v3')
AND NOT condition
;A CASE expression returns a single value. The error in what you posted was that the ELSE branch was trying to return 3 values.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
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 -
Distinct values as input to another query
Can any one help me to write a program to fetch distinct values in query and then insert that distinct values as input to another query
Fetch distinct values:
use distinct keyword
for insert : use the following.
insert into <table_name> select distinct <column_names> from <table_name>; -
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 -
Aggregation level query "value help" = Only Values in InfoProv doesn't work
Hi,
I have a problem with Selection Variable for a BEx Query :
- I'm working with SAP BI 7.0 support package 15
- My query is an input ready query built for an "aggregation level" based on "real time infocube" (Planning);
- Characteristic, I want to filter with variable, has query property Advanced->Query Execution for Filter Value Selection = Only Values in InfoProvider
- Characteristic (info-object) has set the property: Business Explorer tab--> Query Def. Filter Value Selection as Only Values in the info-provider...
My problem is:
when I execute a query,
the Select Values for Variables screen appears
I push on the Select from List button
and Select Values For MyCharacteristic appears...
but it shows me all values in master data table of my characteristic instead of only values in the infoprovider!!!
If I build a query for the Real Time Cube it works correctly, but if the query is built for the aggregation level it doesn't work!
Could someone explain me why it doesn't work correctly?
Thanks in advanced
FedeThanks to Mariana Lazar
30.03.2009 - 12:30:36 CET - Risposta by SAP
Dear Fede,
Regarding the query built on aggregation level please note the following
the aggregation level is always a Virtual Provider built other
InfoProvider and hence it does not have the dimension table and hence
the F4 mode D is not supported.
Therefore when aggregation level is used in a query, F4 does not supportD-mode: 'Only Values in InfoProvider' and all master data values are
displayed in the value list.
Reference from the note
984229 F4 modes for input help as of SAP NetWeaver 2004s BI
4. Since other InfoProviders do not have a dimension table, the system
displays only posted values if you select "Only Posted Values for
Navigation". Otherwise, it displays the values from the master data
table.
Hope this should clarify your doubts. Please let me know if you have
questions else please confirm the message at your earliest convenience.
Thank you for your cooperation and kind regards,
@KR@ Mariana Lazar
Senior Support Consultant
SAP Active Global Support
Netweaver Business Warehouse -
"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 -
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> -
Count distinct values in report builder
i have a situation where i have to count distinct number of customers.
i have a query which returns the list of values of bill_to_customer_id from ra_customer_trx_all table and i have to display only the number of distinct customers. i cant do this in the query because it has to be grouped and i am doing it in an aging report. i have to list the number of distinct customers in each aging period. can anybody please help me how to achieve this in reports 6i.
thankshow can i count distinct values in reports?
the situation is like this
i have a query which lists customer_id, invoice number, amount due
so what i want is to count the distinct customer_id and display the number of distinct customers. one customer_id can be repeated any number of times but i should count it only once. -
Sorting a column does not result in distinct values on Dashboard prompts
Hi,
We have a period column, the records of which are 'JAN-02' , "FEB-02"...."DEC-09". We need sort this column in descending order in Dashboard Prompts. We have another column "Date", which has been used to sort the period column. To achieve this in descending order, we have converted Show Results from “All Values” to “SQL Results” in dashboard prmpts, then entered the below sql.
SELECT "CODE COMBINATIONS"."LINE AC PERIOD" FROM INVOICE_PAYMENTS
order by "CODE COMBINATIONS"."LINE AC DATE" desc
The above sql resulted in non-distinct values as below. Using distinct in the above sql throws syntax error.
Period
JAN-09
JAN-09
JAN-09
FEB-09
FEB-09
How do we get distinct values and in descending order??
Thanks and appreciate any ideas
SuryaGo to advanced tab and check "Use distinct clause" that will fire a distinct to the query.
In the rpd month logical column , there is an option called sort order in the general properties and you need to specify the date column if you need to sort it based on the date column and in the Answers you can simply enable Descending sort order on the same column. That should take care of it
Hope it helps
Thanks
Prash -
Many distinct values vs. few distinct values
Hello,
If I have a table with many millions of records and I query this table with a where clause on a column with a few distinct values, would it perform faster than this column with many, many distinct values? If so, could someone please help me understand why? The where clause would be like this simply:
where column1 = 'xyz'
Could you please answer for the cases where the column IS and ISN'T indexed?
Thanks!arizona9952 wrote:
Are you suggesting that the index might not be used if the column wasn't selective?
SQL> create table tbl1 as select 1 id from dba_source;
Table created.
SQL> create index tbl1_idx on tbl1(id);
Index created.
SQL> exec dbms_stats.gather_table_stats('SCOTT','TBL1');
PL/SQL procedure successfully completed.
SQL> explain plan for
2 select * from tbl1 where id = 1;
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 312383637
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 304K| 892K| 117 (10)| 00:00:02 |
|* 1 | TABLE ACCESS FULL| TBL1 | 304K| 892K| 117 (10)| 00:00:02 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
1 - filter("ID"=1)
13 rows selected.
SQL> update tbl1 set id = rownum;
303652 rows updated.
SQL> commit;
Commit complete.
SQL> exec dbms_stats.gather_table_stats('SCOTT','TBL1');
PL/SQL procedure successfully completed.
SQL> explain plan for
2 select * from tbl1 where id = 1;
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 2835566544
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 4 | 3 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| TBL1_IDX | 1 | 4 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
1 - access("ID"=1)
13 rows selected.
SQL> SY. -
Query help. Any work around?
Hi To all,
Help me on this query.
Table1 : seating_layout
Columns(1) : Seat_no values 50 records i.e.. 1,2,3..50
Ex. Data :
1
2
3.. upto 50, i.e total 50 records
Table : Quotas
Columns(2) : seat_no_from, seat_no_to
Ex. data :
1 5
8 13
I need a query which gives values in a DYNAMIC RECORD GROUP in FORMS6i as below
1,2,3,4,5,8,9,10,11,12,13. i.e. total 11 records.
Im using Version Oracle 8i, Forms 6i. is there any work around to get the result.
Thanks in advance.select map_name,data_entity_name
from ALL_IV_XFORM_MAP_COMPONENTS
where operator_type = 'Table';
or
/* SOURCE - TARGET */
http://www.nicholasgoodman.com/bt/blog/2005/04/01/owb-sources-and-targets-sql/
select
distinct 'TARGET',
comp.map_name,
comp.data_entity_name,
comp.operator_type
from
all_iv_xform_map_components comp,
all_iv_xform_map_parameters param
where
lower(operator_type)
in ('table', 'view', 'dimension', 'cube')
and param.map_component_id = comp.map_component_id
and param.source_parameter_id is not null
UNION
select
distinct 'SOURCE',
t1.c1,
t1.c2,
t1.c3
from
(select
comp.map_name c1,
comp.data_entity_name c2,
comp.operator_type c3,
max(param.source_parameter_id) c4
from
all_iv_xform_map_components comp,
all_iv_xform_map_parameters param
where
lower(operator_type) in
('table', 'view', 'dimension', 'cube')
and param.map_component_id = comp.map_component_id
group by
comp.map_name, comp.data_entity_name, comp.operator_type) t1
where t1.c4 is null
order by 2,1
Maybe you are looking for
-
EEWB : Error while generating extension using wizard
Folks, We are on CRM 5.0, am getting the following error when I try to create few custom fields using EEWB. While creating the project & extension, I gave #temp as the package (dev. class). when I try to start the wizard for creating new fields and p
-
HT4976 How to delete from recents?
How can I delete the emoticons from the 'recent' box?
-
We can group apps why not emails in the same way
It would make so much cense to be able to group e-mails in the same way we group apps by simply holding an e-mail than when it shakes we would drag other emails into it to form a group. Would that make cense ?
-
Can not sign in bbid to connect Q10 with BB link
Hi all, I have managed to signed in bbid in BB link many times but failed. This bbid is in my Q10 and my bb world . There is no any typing mistake. This is a picture for your reference and kind help:
-
Stock Checking in Sales Order.
Hi. How to Put message for Stock across all plants of material entered in SO so that end user will come to know the stock of that particular material in all the plants & he will take decision from where we should order Stock???? Reg. Amol