Distinct count on multiple columns
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production"
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
select distinct USERID,REG_DATE,COUNT(*) CNT from REGISTRATION where TRUNC(REG_DATE)>TO_DATE('01-NOVEMBER-2012','DD-MONTH-YYYY')
and REG_ID not in (select REG_ID from REG_SEG_CAT) group by USERID,REG_DATE
41 27-NOV-12 1
43 27-NOV-12 1
43 27-NOV-12 1any idea how to show count=2 for userid 43
Edited by: 946207 on Dec 4, 2012 2:11 PM
Hi,
How could we know if you don't show us your input data?
Please read SQL and PL/SQL FAQ
Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
Regards.
Al
Similar Messages
-
How to get a distinct count of multiple columns
I've done this before and I'll be darned why I can't recall this.
Table with 3 columns with the primary key defined in column a.
Row a b c
num.
1 020 how abc
2 030 why def
3 010 not ghi
4 040 how abc
5 050 yes def
6 060 why def
So what I want is a count of the unique values for columns b and c as if b and c were actually one field.
So the result of the query would be:
Count = 4 unique rows.
Hopefully I'm making some sort of sense. It's a bit much to ask about the number of occurrences of each duplicate value, I'm sure just getting count of the unique rows of the non-indexed rows will be sufficient. Since the query is meant to be universal for multiple columns of numeric and alphanumeric data and can be expanded for multiple columns, I am simply trying to get a basic skeleton that works for an "on the fly" analysis.Thanks to all of you. I had the idea and just couldn't nail it down. You did it.
All of you understood what I poorly communicated. My apologies for the lack of prep with a table, I was running patches on the system and couldn't dare interrupt it on my laptop and starting Oracle 11 while Micro$lop was patching all sorts of evil code. This is something I'm setting up on my own time so it's a work I'm going to try to be proud of. So there will be plenty of instrumentation and debugging code for timing.
I'd thought of concatenating columns and was worried it wouldn't backport to older Oracle versions (work goes back to 8.1.7) with nulls and other goofy things like long raw fields or lob/clobs plus the other DBs that are at various sites. What I'm trying to do is improve on a crappy data analysis tool SAP provides to use with reporting unique columns. (Basis people could recognize this as DB05). I tried dragging out the SQL that their ABAP/4 language generates from an SQL trace but it was unusable and often dies on internal storage which on most sites is about 4GB per process. Needless to say, the program is wasteful and I'm trying to keep the work on the DB where it belongs and discourage cowboys from doing this in the DB on the fly and at the same time make it simpler for junior members to use while having a semblance of an audit trail.
What I'm trying to do is work out a tool that checks all the crappy secondary indexes that were created by folks who seem to think in ways that are from an alien species not yet speculated about even with the strongest psychedelics. One of them actually decreases performance by a minimum factor of 5. It's not much when it's 5 seconds but when the response time averages about 3 hours beforehand, you can imagine what it was like afterward. In this particular case, the "logic" was that the index needed to be defined by the order of the fields of the select clause. Some myths never die. So it's not easy to work out which ones haven't been used in a long time, so it's down to finding which of the custom ones are actually bad in terms of selectivity. Some of these may have made a little bit of sense when the system was started up, now that some of these have millions of rows instead of a few thousand, thaw tend to expose the flaws in design.
I'm also trying to make this work on multiple DBs such as DB2, MaxDB and (sob) SQL Squealer. The idea is to write this in ABAP code as a utility without the overhead of internal tables in ABAP as some of these tables are many millions of rows and I have to account for the size in memory. (ABAP field sizes in internal memory are generally much larger than the actual DB lengths. so every bit helps!) So I'm trying to create actual SQL on the fly and use it internally without going through the SAP DB interface which limits the type of SQL functions used and all the overhead. It's intended to grab a secondary index and if there are more than 2 fields defined, work it backwards to show unique values for all columns, all columns - 1, all columns - 2 and so on back to the initial column in the index.
Why does this seem important? On Oracle I can generate histograms but those can often screw up SAP. On other DBs, the indexing cardinality is much more important, particularly with DB optimizers that make some odd decisions. So I need evidence I can push to folks who will only understand if there's a plain and simple analysis that explains it (almost) in crayon.
I'm testing null values next (which worked!) but these suggestions all seem to follow the same idea which won't work in ABAP without some serious memory issues. So I'm down to this type of coding:
exec sql.
<dynamically generated true SQL>
end-exec.
rather than using ABAP with their concept of "open SQL" and the DB interface with all the overhead.
RB's suggestion of the UNION ALL wasn't quite what I was looking for BUT it made me think that this would be a nice enhancement for evaluations!
So the candidates that seem to work for what I wanted are as follows:
SQL> SELECT COUNT (MIN (0)) AS distinct_col3_col4_cnt
2 from rb group by b, c;
DISTINCT_COL3_COL4_CNT
7
select count(distinct(b || c)) num_rows from rb;
So thanks also to Frank, APNL and Nimesh for their examples. Now the fun starts as I spec out the processing. -
How do you count the multiple columns of a field in a table
How do you count the multiple columns of a field in a table
Hi,
4396bf34-e890-4202-a6b0-4e08c9ff0e89 wrote:
How do you count the multiple columns of a field in a table
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, 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: https://forums.oracle.com/message/9362002
"Field" isn't a standard database term. Some people say "field" when they mean "column", but I don't think that's what you mean ("How do you count the multiple columns of a column .."). Do you want to know how many times a column is used (as opposed to NULL), or the number of different values in a column? You really need to show what you want. -
Distinct count for multiple fact tables in the same cube
I'm fairly new to working with SSAS, but have been working with DW environments for many years.
I have a cube which has 4 fact tables. The central fact table is Encounter and then I also have Visit, Procedure and Medication. Visit, Procedure and Medication all join to Encounter on Encounter Key. The relationship between Encounter
and Procedure and Encounter and Medication are both an optional 1 to 1. The relationship between Encounter and Visit is an optional 1 to many.
Each of the fact tables join to the Patient dimension on the Patient Key. The users are looking for a distinct count of patients in all 4 fact tables.
What is the best way to accomplish this so that my cube does not talk all day to process? Please let me know if you need any more information about my cube in order to answer this.
Thanks for the help,
AndyHi Andy,
Each distinct count measure cause an ORDER BY clause in the SELECT sent to the relational data source during processing. In SSAS 2005 or later, it creates a new measure group for each distinct count measure(it's a technique strategy for improving perormance).
Besides, please take a look at the following distinct count optimization techniques:
Create Customized Aggregations
Define a Processing Plan
Create Partitions of Equal Size
Use Partitions Comprised of a Distinct Range of Integers
Distribute the Hash of Your UserIDs
Modulo Function
Hash Function
Choose a Partitioning Strategy
For more detail information, please refer to the article below:
Analysis Services Distinct Count Optimization:
http://www.microsoft.com/en-us/download/details.aspx?id=891
In addition, here is a good article about SSAS Best Practices for your reference:
http://technet.microsoft.com/en-us/library/cc966525.aspx
If you have any feedback on our support, please click
here.
Hope this helps.
Elvis Long
TechNet Community Support -
Calculating distinct counts of dimension columns
Hi, OBIEE Gurus. Here's today's question on the quiz show "Can this be done?".
Month
Region
Sales
# Months
# Regions
Jan-2013
East
1000
2
3
Jan-2013
Central
2000
2
3
Jan-2013
West
3500
2
3
Feb-2013
East
1250
2
3
Feb-2013
Central
1925
2
3
Feb-2013
West
3450
2
3
The # Months and # Regions columns are the goal today. There are two months in this analysis (Jan-2013, Feb-2013), out of a total population of 96 months. There are three regions in this analysis (East, Central, West) out of a total population of 7 regions. I want those values (2 and 3, respectively) reflected in the # Months and # Regions columns.
I've tried various combinations of the usual suspects (count, count distinct, sum(count..., sum(count distinct... and so forth) but I haven't found the correct magic spell yet. Any ideas?I found one potential (but somewhat flawed) solution for # Months:
count(distinct aggregate("Facts"."Sales" at "Geographies"."Geography"."Total Locales"))
Region is part of my Geography hierarchy, whose highest level is Total Locales. This says to calculate sales for each row for the Total Locales level, so essentially ignore the Region column. The flaw here is that two different months that just happen to have exactly the same sales will only generate one distinct value of sales, so there is the potential to undercount. (I can get around it with a minor calculation, but that's just another complication.)
It also seems rather clunky, because it has to be modified to accommodate any newly added columns and (basically) create a level-based fact for the highest level of every hierarchy represented except for the column of interest. So it's not very pretty solution.
If you have anything more elegant, bring it on. -
Help retreiving count as multiple columns
I have a table 'decision_makers' with columns
'made_by' - decision maker name
and
'decision_code' - code for decision 'A' -accepted 'R' -rejected 'P' -pending
Assuming the data below in the table
user1 'A'
user2 'A'
user3 'P'
user1 'A'
user2 'R'
user3 'A'
user1 - A
I would like to see the out put in the following format
user A R P
user1 2 0 0
user2 1 1 0
user3 1 0 1
total 4 1 1
I am trying like
select "made_by",count("decision_code") from "decision_makers"
where "decision_code"='A' group by "made_by"
But how can I write this 3 times to get desired result.
Would it be possible by a single query? or do I need to write a sql procedure or 'view'
I am new to Oracle and the above requirement looks complex to me.
Anybody can push me in the right direction?
Thanks
R,
Edited by: user10974770 on Apr 23, 2010 3:35 AMWelcome to the forums!
It looks like you need a PIVOT with ROLLUP to achieve the results you want:
SQL> WITH decision_makers AS
2 (
3 SELECT 'user1' AS MADE_BY, 'A' AS DECISION_CODE FROM DUAL UNION ALL
4 SELECT 'user2' AS MADE_BY, 'A' AS DECISION_CODE FROM DUAL UNION ALL
5 SELECT 'user3' AS MADE_BY, 'P' AS DECISION_CODE FROM DUAL UNION ALL
6 SELECT 'user1' AS MADE_BY, 'A' AS DECISION_CODE FROM DUAL UNION ALL
7 SELECT 'user2' AS MADE_BY, 'R' AS DECISION_CODE FROM DUAL UNION ALL
8 SELECT 'user3' AS MADE_BY, 'A' AS DECISION_CODE FROM DUAL
9 )
10 SELECT DECODE(GROUPING(MADE_BY),1,'total',MADE_BY) AS MADE_BY
11 , COUNT(CASE WHEN DECISION_CODE='A' THEN 1 END) AS A
12 , COUNT(CASE WHEN DECISION_CODE='R' THEN 1 END) AS R
13 , COUNT(CASE WHEN DECISION_CODE='P' THEN 1 END) AS P
14 FROM DECISION_MAKERS
15 GROUP BY ROLLUP(MADE_BY)
16 /
MADE_BY A R P
user1 2 0 0
user2 1 1 0
user3 1 0 1
total 4 1 1Edited by: Centinul on Apr 23, 2010 6:49 AM
Simpler solution -
Distinct count of values which are displayed in two columns in SSAS
Hi,
How is it possible to get distinct count of two columns in fact table, meaning how many different appearances are in both columns.
Please note I DO NOT mean distinct count on the concatenated fields.
I’ll demonstrate with example:
Fact table- deals with CustomerID and SupplierID and deals data.
I need distinct count of companies which are either customer/ supplier in the fact table.
(making a concatenated field and distinct count on that would not give what I need).
Ex: fact :
Deal1, Customer X, Supplier Y …
Deal2, Customer X, Supplier Z …
Distinct count of companies in the above should be 3.
How can this be done?
Thanks
Namnami
Anyone?? There must be a way to do this?!Are you trying to do this using the SSAS model, or just off the data using SQL? If you were to just use SQL I would create two sub queries and union them to remove duplicates.
ie.
SELECT DISTINCT customer FROM table_1
UNION
SELECT DISTINCT supplier FROM table_1
This will give you one unique master list. -
Hi,
I'm trying to build the dax query to determine the distinct count for a column returned by the application of a Filter function.
evaluate(
row("counter",
countrows(
filter(order_summary,
year(order_summary[change_date]) = 2013) )
I need to count the distinct values for an id returned by the Filter function.
Any helps, please? ThanksHi pscorca,
According to your description, you want to calculate the distinct values for records where change_date is 2013. Right?
In this scenario, we can use the DISTINCT() function within COUNTROWS(). Please try the expression below:
=calculate(
countrows(distinct(order_summary[column])),
Filter('order_summary', year(order_summary[change_date])=2013)
Reference:
Distinct Count Measure in PowerPivot using DAX
Related Distinct Count
Best Regards,
Simon Hou
TechNet Community Support -
Getting DISTINCT count from two different columns
Hi all,
I have following query which gives currency code from two different tables. I would like to get the distinct count of currency codes from these two different columns.
SELECT eb.person_seq_id, eb.bonus_amount, eb.currency_cd, ed.currency_cd_host
FROM fr_emp_bonuses eb, fr_emp_details ed, fr_periods p
WHERE eb.person_seq_id = ed.person_seq_id AND ed.period_seq_id = eb.period_seq_id
AND ed.period_seq_id = p.period_seq_id AND p.period_status = 'CURRENT'
AND eb.bonus_amount >= 0 AND eb.person_seq_id = 3525125;
This query gives following result
3525125 240000 USD INR
3525125 0 USD INR
3525125 60000 USD INR
3525125 50000 USD INR
There are two distinct currency codes (USD, INR) and total amount is 350000. So I am looking for a query to give me the following result
3525125 350000 2
Thanks in advanceHi,
Here's one way:
WITH original_query AS
SELECT eb.person_seq_id
, eb.bonus_amount
, eb.currency_cd
, ed.currency_cd_host
FROM fr_emp_bonuses eb
, fr_emp_details ed
, fr_periods p
WHERE eb.person_seq_id = ed.person_seq_id
AND ed.period_seq_id = eb.period_seq_id
AND ed.period_seq_id = p.period_seq_id
AND p.period_status = 'CURRENT'
AND eb.bonus_amount >= 0
AND eb.person_seq_id = 3525125
, unpivoted_data AS
SELECT person_seq_id
, bonus_amount
, currency_cd
FROM original_query
UNION ALL
SELECT person_seq_id
, 0 AS bonus_amount
, currency_cd_host AS currency_cd
FROM original_query
SELECT person_seq_id
, SUM (bonus_amount) AS total_bonus_amount
, COUNT (DISTINCT currency_cd) AS distinct_currency_cds
FROM unpivoted_data
GROUP BY person_seq_id
;There may be a shorter, more efficient way to get the same results, but without knowing more about your tables, I can't tell.
The tricky thing is getting two columns (currency_cd and currencuy_cd_host in this case) counted together. You can't simply say
COUNT (DISTINCT eb.currency_cd) +
COUNT (DISTINCT ed.currency_code_host)That happens to get the correct result with the sample data you posted, but what if you had data like thEe following?
currency_cd currency_cd_host
INR USD
USD INRHere, the count of distinct currency_cds is 2, and the count of distinct currency_cd_hsots is also 2. Does that mean the grand total is 2 + 2 = 4? No, the 2 codes in one column arte the same 2 codes as in the other column. We need to get both currency_cd and currency_cd_hsot into the same column, and then do COUNT (DISTINCT ...) on that combined column. A UNION, as shown above, will certainly do that, starting with your query as you posted it. The query you posted isn't necessarily the best frist step towards this result, however, so there may be a much better approach, depending on your tables.
Edited by: Frank Kulash on Feb 1, 2012 6:21 PM
Here's a slightly shorter, and probably more efficient way to get the same results:
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 2
SELECT eb.person_seq_id
, SUM (eb.bonus_amount) AS total-amount
, COUNT ( DISTINCT CASE
WHEN c.n = 1
THEN eb.currency_cd
ELSE ed.currency_cd_host
END
) AS distinct_currency_cds
FROM fr_emp_bonuses eb
, fr_emp_details ed
, fr_periods p
, cntr c
WHERE eb.person_seq_id = ed.person_seq_id
AND ed.period_seq_id = eb.period_seq_id
AND ed.period_seq_id = p.period_seq_id
AND p.period_status = 'CURRENT'
AND eb.bonus_amount >= 0
AND eb.person_seq_i = 3525125
-- NOTE: no join condition involving c; we really do want a cross-join
GROUP BY eb.person_seq_id
; -
Count Distinct based on another column in the same table
Hello,
My question in short: is is it possible to add a new column to a view which holds the DISTINCT COUNTS of values/domains of another column in the same view?
For example, in the below table the column "Distinct Count of Occurence" shows how many distinct values a person has in the Occurence column. So AAA has 1 and 2 therefore it is 2 distinct values etc.
My issues is that I can retrieve unique values bu Count (Select Occurence)but I can not add the new column that would add the records to the corresponding Persons in the above table.
Is there an easy way to achieve this on the DWH level or should it be done with MDX in the cube?
ThanksHi,
Below a solution to use the view by adding a column with window functioning, maybe this will help.
CREATE TABLE #TMP
PERSON VARCHAR(10),
OCCURENCE SMALLINT
--DROP TABLE #TMP
INSERT INTO #TMP(PERSON,OCCURENCE)
VALUES
('AAA','1'),
('AAA','2'),
('BBB','1'),
('BBB','1'),
('BBB','1'),
('CCC','1'),
('CCC','2'),
('CCC','3');
--TRUNCATE TABLE #TMP
WITH CTE
AS
SELECT PERSON
,OCCURENCE
,ROW_NUMBER() OVER(PARTITION BY PERSON ORDER BY OCCURENCE) AS RN
FROM #TMP
SELECT PERSON, MAX(RN) AS RN
FROM CTE
GROUP BY PERSON
Regards,
Reshma
Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered -
Counting Occurences over multiple columns
I have searched the forums and found how to calculate the number of occurrences of a word in a single column.
I am working on a sales project and I need to calculate the number of occurrences for a specific sales agent in multiple columns. Then a total of the sales next to the occurrences
Column 1 will be the sales agent for a home buyer.
Column 2 will be the sales agent for a home seller.
I need to find out how many times a specific agent represents both buyers and sellers.
Then I need a total of all the sales for each of the agents.
I have very large tables with multiple categories for each sale.
Yvan you seem to be the guru.
Please help.
All the best,
WillWill,
Jerry has given you a good solution in general terms but there are some ambiguities in your question.
For example, your question suggests there is transaction amount column, as one might expect, but did not specify if these amounts are listed in separate buyer/seller columns. The solution below assumes they are in a single column.
An auxiliary column (hidden) was added to the Data Table to determine whether or not an agent represented both buyer and seller. The agent's name appears in this column if he/she did, and the formula is:
=IF(OR(Sell Agt="",Buy Agt=""),"",Sell Agt)
The Summary table raises the question of whether the agent's amount is doubled when he/she represents both buyer and seller. Here again, an assumption was made, namely, that it does not. If this is incorrect, the last segment (after the "-" sign) of the formula below can be dropped:
=IF(A="","",SUMIF(Sales Data :: Sell Agt, A, Sales Data :: Trans Amt)+SUMIF(Sales Data :: Buy Agt, A, Sales Data :: Trans Amt)-SUMIF(Sales Data :: 'Buyer & Seller Rep', A, Sales Data :: Trans Amt))
And finally, the number of times an agent represented both buyer and seller:
=IF(COUNTIF(Sales Data :: 'Buyer & Seller Rep', A)=0,"",COUNTIF(Sales Data :: 'Buyer & Seller Rep', A))
I hope this represents your situation and that it answers your questions.
pw -
Distinct count using lookup table
How can I get a distinct count of column values using a different table?
Let's say I want to get a distinct count of all "company_name" records in table "emp" that corespond (match) with "lookup" table, "state" category.
What I want is to find counts for all companies that have a value of "california" in the "state" column of the "lookup" Table. I want the output to look like:
Sears 17
Pennys 22
Marshalls 6
Macys 9
I want the result to show me the company names dynamically as I don't know what they are, just that they are part of the "state" group in the lookup Table. Does this make sense?
MMark,
In the future you might consider creating test cases for us to work with. Something similar to the following where sample data is created for each table as the union all of multiple select statementsselect 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual;
select 'INIT_ASSESS' rfs_category
, 1 val
from dual union all
select 'JOB_REF', 1 from dual union all
select 'JOB_REF', 1 from dual union all
select 'SPEC_STA', null from dual;Then we can either take your select statements and make them the source of a CTAS (create table as) statementcreate table lookup as
select 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual;, or include them as subfactored queries by using the with statement:with lookup as (
select 'INIT_ASSESS' lookup_type
, 1 lookup_value
, 'Initial Assessment' lookup_value_desc
from dual union all
select 'JOB_REF', 2, 'Job Reference' from dual union all
select 'SPEC_STA', 3, 'SPEC STA' from dual
), RFS as (
select 'INIT_ASSESS' rfs_category
, 1 val
from dual union all
select 'JOB_REF', 1 from dual union all
select 'JOB_REF', 1 from dual union all
select 'SPEC_STA', null from dual
select lookup_value_desc, count_all, count_val, dist_val
from lookup
join (select rfs_category
, count(*) count_all
, count(val) count_val
, count(distinct val) dist_val
from RFS group by rfs_category)
on rfs_category = lookup_type;Edited by: Sentinel on Nov 17, 2008 3:38 PM -
Post Author: Donamese
CA Forum: General
I am trying to create a report that is split between 3 companies and all states using a distinct count of individuals (as there are duplicates in the data pool). I would like the report to look like:
State Company 1 Company 2 Company 3
AL 0 16 5
AR 3 9 4
AZ 5 0 7
Currently I can only get it to list vertical like:
Company 1
AL 0
AR 3
AZ 5
Company 2
AL 16
etc....
I am unable to get the formating of multiple columns with the grouping. Is it possible? And ifPost Author: rookie10
CA Forum: General
Try inserting a Cross Tab in the Report or page header. Its pretty much like a pivot table.
Use State as the Row, Company as the Column, Individuals as Summarized field using Distinct Count as the summary type.
In customized style part of the cross tab you can hide some of the totals and such to get pretty close to the report above - supress subtotals and such.
Hope this works for you. I was pretty excited when I found this feature in Crystal.
Rookie10 -
SELECT in SELECT returning multiple columns ?
10.2.0.3 version.
I am trying to tune this query
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
(SELECT A2.DESCRSHORT FROM PS_ACAD_PROG_TBL A2
WHERE A2.INSTITUTION = 'AUAO1' AND A2.ACAD_PROG = A.ACAD_PROG AND A2.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A2.INSTITUTION AND ACAD_PROG = A2.ACAD_PROG),
as you can see it reading the table PS_ACAD_PROG_TBL two time to get two cloumns DESCR (alias A1) and DESCRSHORT (alias A2) exactly with the same where condition.
I am trying to replace it with just one select returning multiple columns like this
SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
(SELECT A1.DESCR, A1.DESCRSHORT FROM PS_ACAD_PROG_TBL A1
WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
but I am getting ORA-00913: too many values.
Please help on how to get around this. Thanks in advance.William,
On similar lines I am struggling with the below query based on your suggestions.
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Aug 5 14:17:21 2009
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> WITH arch_dup AS
2 (SELECT a.file_id,
3 a.sale_start,
4 a.activity_start,
5 a.activity_end,
6 a.item_code_cust,
7 a.division,
8 (SELECT MAX (DISTINCT (NVL (b.advertised, 'No')))
9 FROM ah_cust_gis_arch_stg b
10 WHERE b.file_id = a.file_id
11 AND NVL (b.sale_start, 'NULL') = NVL (a.sale_start, 'NULL')
12 AND NVL (b.activity_start, 'NULL') = NVL (a.activity_start, 'NULL')
13 AND NVL (b.activity_end, 'NULL') = NVL (a.activity_end, 'NULL')
14 AND b.item_code_cust = a.item_code_cust
15 AND b.division = a.division) advertised,
16 COUNT (*)
17 FROM ah_cust_gis_arch_stg a
18 WHERE a.file_id = 209
19 AND a.status_id = 21
20 GROUP BY a.file_id, a.sale_start, a.activity_start, a.activity_end, a.item_code_cust, a.d
ivision
21 HAVING COUNT (*) > 1)
22 SELECT dup.*,
23 (SELECT activity_id
24 FROM (SELECT activity_id,
25 ROW_NUMBER () OVER (ORDER BY (activity_retail / activity_mult)) rnk
26 FROM ah_cust_gis_arch_stg
27 WHERE status_id = 21
28 AND NVL (sale_start, 'NULL') = NVL (dup.sale_start, 'NULL')
29 AND NVL (activity_start, 'NULL') = NVL (dup.activity_start, 'NULL')
30 AND NVL (activity_end, 'NULL') = NVL (dup.activity_end, 'NULL')
31 AND item_code_cust = dup.item_code_cust
32 AND division = dup.division
33 AND file_id = 209
34 AND UPPER (NVL (advertised, 'N')) = dup.advertised)
35 WHERE rnk = 1) activity_id
36 FROM arch_dup dup;
AND UPPER (NVL (advertised, 'N')) = dup.advertised)
ERROR at line 34:
ORA-00904: "DUP"."ADVERTISED": invalid identifierCan you throw some light on what to do to make the outer query columns available to inner query?
Thanks,
Raj. -
"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
Maybe you are looking for
-
Install Issues, Bootable USB, 2011 13" MBA, "No Bootable Drive" Error
13" 2011 MBA i5 Processor 4 GiB RAM, etc. Running 10.7.3 I was forced to resort to wiping and reinstalling OSX after a rather catastrophic series of pranks from my brother. Yet, using the exact same methods, at least, on the software end, I was unabl
-
SENDING REPORTS O/P THRU E-MAIL: ATTACHMENT NAME NOT VISIBLE
Hi, I have created a report program which will convert report o/p to excel sheet and send the attachment to the mail id provided in the selection screen. Here in this case the mail is going perfectly, and the attachment also but the problem is the at
-
Ive literally tried everything no joke
-
Macbook Air late 2008 running extremely slow
I just bought a Macbook Air late 2008 online & when i recieved it it had been wiped out and set back to it's original favroty settings. The battery is completely dead so it must be charged at all times. Everytime I use the laptop it is extremely slow
-
FYI - Importing Translated XML (XLIFF) into Captivate 5
I just want to make a point about an issue I've come across when translating a Captivate 5 project. On exporting to XML - which is actually a mono-lingual XLIFF format in reality, this is where the problems start. A true XLIFF file contains both sour