SQL Count helps
Hello worldI need to display the SPER_STATUS_TEXT count as 0 if there is no data from query below. Could someone help me please
SQL > SELECT a.sper_status_text, COUNT (*)
2 from (SELECT sper.assettxt,
CASE 3
4. WHEN sper.sper_status_text = "assessment" said.
5 THEN
6 'confirmed assessment '.
7. WHEN sper.sper_status_text AS "update - rated %".
8 THEN
9 "update - rated up to."
10. WHEN sper.sper_status_text AS "update - % evaluated.
11. CAN
12 'update - rated down"
13 ELSE
14 "other responses.
15 END
16 sper_status_text
17 zzcus.zzcus_sper_data sper
18 WHERE sper.sper_dates = ' 20100801-20100831'
19 AND sper.customer_id = 'NATFINS. '
20 AND sper.task_inquiry_type = "Vendor Comparison"
21 AND sper.assettxt <>'! MAD
(22) a
23 GROUP BY a.sper_status_text
ORDER 24 (CASE
25. WHEN a.sper_status_text = "Said assessment" THEN 1
26. WHEN a.sper_status_text = "update - evaluated until ' THEN 2
27. WHEN a.sper_status_text = 'Update - rated down' THEN 3
28 4 SOMETHING ELSE
END 29);
Results:
SPER_STATUS_TEXT COUNT (*)
------------------------ ----------
Claims assessment 2
I need to display as below (if there no data I need to display the number as 0)
SPER_STATUS_TEXT COUNT (*)
------------------------ ----------
Claims assessment 2
Updated - evaluated up to 0
Updated - rated low 0
Other answers 0
Please advice
You can get this. Using the TYPE clause.
SQL>
SQL> CREATE TABLE ZZCUS_SPER_DATA1
2 (
3 SPER_STATUS_TEXT VARCHAR2 (30)
4 ,TASK_INQUIRY_TYPE VARCHAR2 (100)
5 );
Table created.
SQL>
SQL> INSERT INTO ZZCUS_SPER_DATA1
2 VALUES (
3 'Data Updated', 'Descriptive Data Challenge - Maturity date / Redemption date');
1 row created.
SQL>
SQL> INSERT INTO ZZCUS_SPER_DATA1
2 VALUES ('Data Updated', 'Descriptive Data Challenge - Ticker / Local Code');
1 row created.
SQL>
SQL> SELECT *
2 FROM ( SELECT A.SPER_STATUS_TEXT, COUNT (*) CNT
3 FROM (SELECT CASE
4 WHEN SPER.SPER_STATUS_TEXT = 'Data Confirmed'
5 THEN
6 'Data Item Confirmed'
7 WHEN SPER.SPER_STATUS_TEXT LIKE 'Data Updated'
8 THEN
9 'Data Item Updated'
10 ELSE
11 'Other Responses'
12 END
13 SPER_STATUS_TEXT
14 FROM ZZCUS_SPER_DATA1 SPER
15 WHERE 1 = 1
16 AND SPER.TASK_INQUIRY_TYPE LIKE 'Descriptive Data Challenge%') A
17 GROUP BY A.SPER_STATUS_TEXT
18 ORDER BY (CASE
19 WHEN A.SPER_STATUS_TEXT = 'Data Item Confirmed' THEN 1
20 WHEN A.SPER_STATUS_TEXT = 'Data Item Updated' THEN 2
21 WHEN A.SPER_STATUS_TEXT = 'Other Responses' THEN 3
22 ELSE 4
23 END))
24 MODEL
25 DIMENSION BY (SPER_STATUS_TEXT)
26 MEASURES (CNT)
27 RULES
28 (CNT ['Data Item Confirmed'] = NVL (CNT[CV ()], 0),
29 CNT ['Data Item Updated'] = NVL (CNT[CV ()], 0),
30 CNT ['Other Responses'] = NVL (CNT[CV ()], 0));
SPER_STATUS_TEXT CNT
------------------- ----------
Data Item Updated 2
Other Responses 0
Data Item Confirmed 0
3 rows selected.
SQL>
G.
Tags: Database
Similar Questions
-
Dear friends,
Version of DB - 11.1.0.7... , I'm stuck with SQL basics today... need your help...
The slot SQL tells me "cache them locks library" in the database that I will put up as a proactive measure.
I'll be it works via shell script and include the table gv instance_name $ instance ... I'm a little confused as to how a 3rd table "gv$ instance ' can be introduced into the query in order to make the instance_name in the result set...
SELECT * FROM)
SELECT / * + LEADING (a) USE_HASH (u) * /.
instance_name, INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.
DECODE (sql_opcode, 1, 'CREATE TABLE', 2, 'INSERT') as "order."
Event, mod(P1,16) p1, p2, p3
COUNT (*) totalseconds
, SUM (CASE WHEN wait_class = 'Application' THEN 1 ELSE 0 END) 'Application '.
Of
(SELECT
a.*
, TO_CHAR (CASE WHEN session_state = 'WAITING' THEN ELSE null END p1, '0XXXXXXXXXXXXXXX') p1hex
, TO_CHAR (CASE WHEN session_state = "PENDING" THEN p2 ELSE null END, '0XXXXXXXXXXXXXXX') p2hex
, TO_CHAR (CASE WHEN session_state = "PENDING" THEN ELSE null END p3, '0XXXXXXXXXXXXXXX') p3hex
SGS $ active_session_history one) a
u dba_users
WHERE
a.user_id = u.user_id
AND sample_time BETWEEN sysdate-90 /(24*60) AND sysdate
- AND a test of ('library cache lock', 'library cache pin")
AND event like '% library '.
GROUP BY
INST_ID select, blocking_inst_id, blocking_session, username, session_id, sql_id, current_obj #,.
DECODE (sql_opcode, 1, 'CREATE TABLE', 'INSERT', 2),
event, mod (p1, 16), p2, p3
Having count (*) > 5
ORDER BY
TotalSeconds DESC
, INST_ID select, blocking_session, username, session_id, sql_id, current_obj #, 'Order', event
)
WHERE
ROWNUM < = 20
/
replace
instance_name
by
(select instance_name gv$ instance where INST_ID select = a.inst_id) instance_name
or select... in... a, u, gv$ instance where... and gv$ instance.inst_id (+) = a.inst_id...
-
GROUP OF + SQL COUNT + SUM
Hello
I have a table, it has 2 colunms, (name, number)
name number
B1 7
B1 7
B1 28
B1 28
B1 28
B2 7
B2 28
B3 7
. .
. .
.
.
I want to see below
number
name sum 7sum 28sum
5 2 3 B1
2 1 1 B2
B3...
.
.
.
.
.
Can you help me
THANK YOU VERY MUCH FOR HELPLike this?
SQL> ed Wrote file afiedt.buf 1 with t as (select 'B1' as name, 7 as num from dual union all 2 select 'B1', 7 from dual union all 3 select 'B1', 28 from dual union all 4 select 'B1', 28 from dual union all 5 select 'B1', 28 from dual union all 6 select 'B2', 7 from dual union all 7 select 'B2', 28 from dual union all 8 select 'B3', 7 from dual) 9 -- 10 -- end of test data - use query below 11 -- 12 select name 13 ,count(*) 14 ,sum(decode(num,7,1,0)) as sum7 15 ,sum(decode(num,28,1,0)) as sum28 16 from t 17 group by name 18* order by 1 SQL> / NA COUNT(*) SUM7 SUM28 -- ---------- ---------- ---------- B1 5 2 3 B2 2 1 1 B3 1 1 0
-
error of dynamics of the associative array (pl/sql), please help
Function down I can hard-coded but not able to go to dynamically can u please friends
CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2) RETURN VARCHAR2
AS
ARR_LIST APEX_APPLICATION_GLOBAL. VC_ARR2;
Typ_array. ARRAY TYPE IS VARCHAR2 (16);
array_final typ_array;
V_ARRAY VARCHAR2 (2000);
v_out VARCHAR2 (2000);
v_result VARCHAR2 (2000);
BEGIN
ARR_LIST: = APEX_UTIL. STRING_TO_TABLE (P_YYMM, ',');
Select LISTAGG (fid_value, ',') IN GROUP (ORDER BY fid_value) BY v_array
of filter_detail, filter_master
where fil_id = fid_fil_id
and fil_position = 15
AND NVL (fid_ACTIVE, 'Y') = 'Y ';
array_final: = typ_array (v_array); Commented (1102,1101,1012,1011,1010,1009,1008,1007,1006,1005,1004,1003,1002,1001);
I'm looping 1.array_final.count
If array_final (i) in (arr_list (I)) then v_result: = '1';--Commented--(1002,1003,1007)
Another v_result: = '0';
end if;
v_out: = v_out | v_result;
end loop;
Return v_out;
END;
my output is
00000001000110
Published by: V on March 23, 2011 21:42
Published by: V on March 23, 2011 22:24
Published by: V on March 23, 2011 23:00
Published by: V on March 24, 2011 12:57 AMHello
Please check below, hope this helps.
SQL> SQL> DROP TABLE tmp 2 / Table dropped SQL> CREATE TABLE tmp ( col1 NUMBER) 2 / Table created SQL> INSERT INTO tmp 2 SELECT 1001 FROM DUAL UNION 3 SELECT 1002 FROM DUAL UNION 4 SELECT 1003 FROM DUAL UNION 5 SELECT 1004 FROM DUAL UNION 6 SELECT 1005 FROM DUAL UNION 7 SELECT 1006 FROM DUAL UNION 8 SELECT 1007 FROM DUAL UNION 9 SELECT 1008 FROM DUAL UNION 10 SELECT 1009 FROM DUAL UNION 11 SELECT 1010 FROM DUAL UNION 12 SELECT 1011 FROM DUAL UNION 13 SELECT 1012 FROM DUAL UNION 14 SELECT 1101 FROM DUAL UNION 15 SELECT 1102 FROM DUAL 16 / 14 rows inserted SQL> COMMIT 2 / Commit complete SQL> CREATE OR REPLACE FUNCTION FN_SUBSCRIPTION_BEHAVIOUR(P_YYMM IN VARCHAR2) 2 RETURN VARCHAR2 AS 3 ARR_LIST APEX_APPLICATION_GLOBAL.VC_ARR2; 4 TYPE typ_array IS TABLE OF VARCHAR2(16); 5 array_final typ_array; 6 V_ARRAY VARCHAR2(2000); 7 v_out VARCHAR2(2000); 8 v_result VARCHAR2(2000); 9 BEGIN 10 select LISTAGG(col1, ',') WITHIN 11 GROUP( 12 ORDER BY col1) 13 INTO v_array 14 from tmp; 15 ARR_LIST := APEX_UTIL.STRING_TO_TABLE(v_array, ','); 16 for i in 1 .. ARR_LIST.count loop 17 if (INSTR(P_YYMM, ARR_LIST(i)) > 0) then 18 v_result := '1'; 19 else 20 v_result := '0'; 21 end if; 22 v_out := v_out || v_result; 23 end loop; 24 return v_out; 25 END; 26 / Function created SQL> DECLARE 2 l_out VARCHAR2(2000); 3 BEGIN 4 l_out := FN_SUBSCRIPTION_BEHAVIOUR('1002,1003,1004'); 5 dbms_output.put_line(l_out); 6 END; 7 / 01110000000000 PL/SQL procedure successfully completed SQL>
Ameya
-
SQL count (*) with Group of
Hello
I need help to fix this SQL.
Fields in the table are like that.
Basically I want the values of user_id, user_name, last time the logged-in user and total number of times the userID(PK) user_id user_name login_time(timestamp)
the above query is to give the result set with user_id, user_name, last time that the user logged on, but how can I include count (*) Group of user_id in the sql aboveselect distinct user_id , user_name, login_date from USER_LOGIN where login_date in (select max(login_date) from USER_LOGIN group by user_id)
the sql above does not work.select distinct user_id , user_name, login_date, count(*) from USER_LOGIN where login_date in (select max(login_date) from USER_LOGIN group by user_id) group by user_id
can you help me to get the number of records by user_id group.
Thank you
SKHello
Looks like you want something like this:
SELECT user_id , user_name , MAX (login_time) AS last_login_time , COUNT (*) AS total_rows FROM user_login GROUP BY user_id , user_name ;
This assumes that user_login is off standard (like him are often seen), such that every row of the same user_id will also have the same user_name.
I hope that this answers your question.
If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. -
Hello
I have the table and professorid, studentid, classid.
Please provide the sql code to find professor_id which hosts up to students.
with t as)
Select professor_id,
ROW_NUMBER() over (order by count (distinct student_id) desc) rn
from your_table
Professor_id group
)
Select professor_id
t
where rn = 1
/
However, if there is a tie and a teacher number max of students has more meanings will select one of them. If you want that all teachers use:
with t as)
Select professor_id,
DENSE_RANK() over (order by count (distinct student_id) desc) rn
from your_table
Professor_id group
)
Select professor_id
t
where rn = 1
/
SY.
-
SQL Query help find albums from sale
Hi Experts,
I have the following data and the need to find the book Top sold in each type.
Book Type QTY
20 Help the 3 10 Kitchen 1 5 Navigation 2 30 Help the 4 Please let me how can know we get this simple SQL help?
Thank you
Bharat
Hello
Bharat Hegde wrote:
Hi all
I tried to use Dense_rank as below. But it gives me the top selling books. I need high library in each type...
This looks like a job for 'PARTITION BY type
For example:
WITH got_rnk AS
(
SELECT b.bid, b.type
SUM (o.quantity) AS total_quantity
DENSE_RANK () OVER ( PARTITION BY b.type
ORDER OF SUM (o.quantity) / / DESC
) AS rnk
B BOOK
o order1
WHERE b.bid = o.bid
GROUP BY b.bid, b.type
)
SELECT total_quantity, type submission
OF got_rnk
WHERE rnk = 1
;
. Aggregate functions (such as the SUM, above) are calculated before analytical functions, so an analytic function (such as DENSE_RANK above) may depend on an aggregate function; you don't need a separate subquery for that.
-
SQL Count query - Assistance needed
Hello
Hoping someone can point me in the right direction. Here's the query I have so far. What I'm trying to do is to compare and add the names of the skills of individuals. My current query will count them, however, I need to take a step further where if the person has a name of "Spanish" skills can only which is counted and not their names other skills.
Current query:
WITH AS TBL1
(SELECT
TRIM (A.NWIE_ID) AS NWIE_ID,
A.AGENT_NM,
B.BUSINESS
Of
LIGHTHOUSE. IEX_AGENTS A JOIN
LIGHTHOUSE. TBL_GEN_MU_BUSINESS B
ON A.MU_ID = B.MU_ID
WHERE B.BUSINESS IN ('PL_LEGACY'));
TBL2 ACE
(SELECT
TRIM (C.USER_ID) AS USER_ID,
TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,
CASE
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 2) THEN "basic".
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 7) THEN "moderate."
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL < = 10) THEN 'complex '.
WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.
Another null
END AS SKILL_NM
THE LIGHTHOUSE. C CFG_PERSON_SKILL_HIST
)
SELECT
WEEKBEGINNING,
SKILL_NM,
COUNT (DISTINCT NWIE_ID) TOTAL_SKILLED
Of
TBL1,
TBL2
WHERE TBL1. NWIE_ID = TBL2. USER_ID
AND SKILL_NM NOT IN ('NULL %')
SKILL_NM GROUP, WEEKBEGINNING
ORDER OF WEEKBEGINNING, SKILL_NM
Create the Table data:
CREATE TABLE IEX_AGENTS
(
AGENT_NM VARCHAR2 (20).
NWIE_ID CHAR (8),
NUMBER OF MU_ID (5)
)
CREATE TABLE TBL_GEN_MU_BUSINESS
(
BUSINESS VARCHAR2 (100),
NUMBER OF MU_ID (5)
)
CREATE TABLE CFG_PERSON_SKILL_HIST
(
USER_ID VARCHAR2 (8).
DATE OF ASOF_DT,
SKILL_NM VARCHAR2 (64).
NUMBER OF SKILL_LEVEL (10)
)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Marcelle, Athalie", "MARCELA1", 5)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ('Lister, Laura", 'LISTERL3', 6)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Purvis, Bradley", 'PURVIB1', 4)
INSERT INTO IEX_AGENTS (AGENT_NM, NWIE_ID, MU_ID) VALUES ("Cannon, Mark", "CANNON1", 4)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 5)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 6)
INSERT INTO TBL_GEN_MU_BUSINESS (BUSINESS, MU_ID) VALUES ('PL_LEGACY', 4)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacy', 1).
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/9/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 3)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/9/2014 12:00 ',' PLSCLegacySpanish', 6)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/9/2014 12:00 ',' PLSCLegacySpanish', 2)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('PURVIB1', 3/19/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('LISTERL3', 3/19/2014 12:00 ',' PLSCLegacy', 2)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('MARCELIA1', 3/9/2014 12:00 ',' PLSCLegacy', 10)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacy', 7)
INSERT INTO CFG_PERSON_SKILL_HIST (USER_ID, ASOF_DT, SKILL_NM, SKILL_LEVEL) VALUES ('CANNON1', 3/19/2014 12:00 ',' PLSCLegacySpanish', 7)
Results of the current query:
WEEKBEGINNING SKILL_NM TOTAL_SKILLED 07/03/2014 12:00:00 AM Foundational 1 07/03/2014 12:00:00 AM Complex 1 07/03/2014 12:00:00 AM Moderate 2 07/03/2014 12:00:00 AM Spanish 3 14/03/2014 12:00:00 AM Foundational 1 14/03/2014 12:00:00 AM Complex 2 14/03/2014 12:00:00 AM Moderate 1 14/03/2014 12:00:00 AM Spanish 1 Desired results:
WEEKBEGINNING SKILL_NM TOTAL_SKILLED 07/03/2014 12:00:00 AM Foundational 0 07/03/2014 12:00:00 AM Complex 0 07/03/2014 12:00:00 AM Moderate 1 07/03/2014 12:00:00 AM Spanish 3 14/03/2014 12:00:00 AM Foundational 1 14/03/2014 12:00:00 AM Complex 2 14/03/2014 12:00:00 AM Moderate 0 14/03/2014 12:00:00 AM Spanish 1 WITH ACE TBL1)
SELECT TRIM (A.NWIE_ID) AS NWIE_ID,
A.AGENT_NM,
B.BUSINESS
OF IEX_AGENTS HAS
JOIN THE
TBL_GEN_MU_BUSINESS B
ON A.MU_ID = B.MU_ID
WHERE B.BUSINESS IN ("PL_LEGACY")
),
(ACE TBL2)
SELECT USER_ID, TRIM (C.USER_ID)
TRUNC (ASOF_DT, 'IW') AS WEEKBEGINNING,
CASE
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 2)="" then="">=>
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 7)="" then ="">=>
WHERE (SKILL_NM = 'PLSCLegacy' AND SKILL_LEVEL<= 10)="" then ="">=>
WHERE (SKILL_NM = "PLSCLegacySpanish") THEN 'Spanish '.
END AS SKILL_NM
OF CFG_PERSON_SKILL_HIST C
),
(AS TBL3)
SELECT USER_ID,
WEEKBEGINNING,
SKILL_NM,
COUNT)
SKILL_NM SEPARATE CASE
WHEN 'Spanish', 1
END
) HAS_SPANISH OVER (PARTITION BY USER_ID, WEEKBEGINNING)
FOR TBL2
)
SELECT WEEKBEGINNING,
SKILL_NM,
COUNT)
SEPARATE CASE
WHEN HAS_SPANISH = 0 THEN NWIE_ID
WHEN SKILL_NM = "Spanish" THEN NWIE_ID
END
) TOTAL_SKILLED
FROM TBL1;
TBL3
WHERE TBL1. NWIE_ID = TBL3. USER_ID
AND SKILL_NM NOT IN ('NULL %')
SKILL_NM GROUP,
WEEKBEGINNING
ORDER OF WEEKBEGINNING,
SKILL_NM
/
WEEKBEGINNING SKILL_NM TOTAL_SKILLED
---------------------- ------------ -------------
03/03/2014 12:00:00 am founders 0
03/03/2014 moderate from 12:00:00 am 0
03/03/2014 12:00:00 am 2 Spanish
17/03/2014 12:00:00 am complex 1
17/03/2014 12:00:00 am basic 1
17/03/2014 12:00:00 am Spanish 16 selected lines.
SQL >
SY.
-
SQL - select Help - box When? Return value of the second Table?
-Next to people on this forum I am probably somewhere between a beginner and an intermediate SQL user.
Ive been using a case when stated in plsql to find "all who has status in any program was canceled during a specific time, but have become or are still active in another program"
So, Im actually trying to return a value from another table in a case where, but this isn't anthing taste other than a text declared as 'Yes' or 'no '.
This is the select statement - y at - it another way to do it where I can get the results I need?
-case when pp.party_id in (select pp1.party_id - cancelled active clients in another program)
of asa.program_participation pp1,.
ASA.curr_prog_participation_status cpps1
where pp1.program_participation_id = cpps1.program_participation_id
and pp1.party_id = pp.party_id
and cpps1.code_value = 'Act')
So 'Yes' is still 'No' end as Active_in_Other_Prg
So - instead of 'Yes', I want essentially the program they are active or pp1.program_id, another null
It is possible that the client can be active in more than one program as well.
Any help is greatly appreciated, I explored with if and decodes but I can't get anything to work.
Ben
Looks like an outer join. See doc ora: joins at
Select p
q.party_id
q.program_id
of table_with_party_id p
, (select pp1.party_id - cancelled active clients in another program)
pp1.program_id
of asa.program_participation pp1,.
ASA.curr_prog_participation_status cpps1
where pp1.program_participation_id = cpps1.program_participation_id
and pp1.party_id = pp.party_id
and cpps1.code_value = 'ACT') q
where p.party_id = q.party_id (+)
Note: In the example above shoudn't it be a space between the (and +), but the forum software automatically converts to
The outer join will connect display all records in the table p and q records only if fits the party_id, IE q.party_id and q.program_id will be null if there is no match.
Edit: adding program_id
-
Morning all,
I need assistance with regard to the PL/SQL code.
Question: How many cases was activated from Direct treatment information/advice within 8 weeks?
Sample data:
MEMBER_ID CASE_ID SP_CODE SP_NAME SP_SUBTYPE_CODE SP_SUBTYPE_NAME REFERRAL_DATE SERVICE_DATE 000000001 2013858 1001 Info & advice 1001 Information - 25/09/2012 000000001 2013858 1005 Direct treatment 1022 Seamless 10/01/2012 10/01/2012 I need to count the number of the place where CASE_ID SP_CODE = '1001 ' and then a SP_CODE = '1005' as the program installation, then the difference between SERVICE_DATE for ' 1001' and for '1005' REFERRAL_DATE is within 8 weeks? I hope this makes sense?
Hello
One way is to use a Sun-query EXISTS, like this:
SELECT COUNT (case_id) AS cnt - or COUNT (DISTINCT case_id)
FROM table_x m
WHERE sp_code = 1005
AND THERE ARE)
SELECT 1
FROM table_x
WHERE sp_code = 1001
AND case_id = m.case_id
AND service_date > = m.service_date - (8 * 7)
AND service_date< > >
)
;
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. Point where the query above will not and explain how to get good results in these places.
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
The combination (case_id, sp_code) is unique? What happens if a case_id has, say, 1001 multiple s all less than 8 weeks before the same 1005?
Member_id (or one of the other columns not in the above query) plays no role in this problem?
-
SQL statement Help Find County
I have an Oracle table with lot of columns and I want to check if 3 of my columns contain all values (I don't like the real value, there, I just want to know how many of them have a value). Allows so say for example:
Table columns: ID, A, B, C
These conditions would be true... value exists in both A AND B, A AND C or B AND C columns. If a value exists in A and not B or C, then it should not be counted. Similarly, if a value exists in B and not A or C, or there is a value C and not A or B, then he shouldn't have counted.
----------------------
| ID | A | B | C |
----------------------
| 1. X | X | | <-true
| 1. X | X | X | <-true
| 1. X | | X | <-true
| 1 | | X | X | <-true
| 1. X | | | <-false
| 1 | | X | | <-false
| 1 | | | X | <-false
| 1 | | | | <-false
| 2. X | X | | <-true
| 2. X | X | X | <-true
| 2. X | | X | <-true
| 2 | | X | X | <-true
| 2. X | | | <-false
| 2 | | X | | <-false
| 2 | | | X | <-false
| 2 | | | | <-false
----------------------
Static values will be my ID. I want to check against 2 ID who I know will always be the case. I tried to write, but I'm sure I'm doing something wrong because my count was very high (about 1.7 million records over 2 million).
That's what I wrote:
Select count (*)
FROM table1
where (ID = "1" or ID = "2")
(A is not null and B is not null)
or (A is not null and is not null)
or (B is not null and is not null);
Thanks for your help!
Published by: 973560 on March 14, 2013 12:03Hello
One way to see how many rows have values in at least 2 of the following columns:
SELECT COUNT (*) AS cnt FROM table1 WHERE id IN ('1', '2') -- is id really a string? AND NVL2 (a, 1, 0) + NVL2 (b, 1, 0) + NVL2 (c, 1, 0) >= 2 ;
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in the palces.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
Dear Experts,
I need help, writing / editing PL/SQL procedure below. My task is to rebuild indexes on tables that were not rebuilt during the last 24 hours. The "select" statement of down gives me the list of all the names of tables whose indexes are not rebuilt in last 24 hours (maint.index_rebuild is a custom table, we built to capture the rebuild index timings).
maint.online_reorg procedure done index rebuild. I need this procedure to run on all tables (returned by the select statement). How can I get the modified procedure to get what I'm looking for below. Enjoy your entries.
declare cursor c1 is select distinct table_name from maint.index_rebuild where start_time <= SYSDATE-1; begin for i in c1 loop maint.online_reorg('OWNER','table name from cursor result set'); end loop; end; /
declare cursor c1 is select distinct table_name from maint.index_rebuild where start_time <= SYSDATE-1; begin for i in c1 loop maint.online_reorg('OWNER',i.table_name); end loop; end;
will do what you ask. As others have pointed out, however, what you're trying to do is strongly discouraged. Reconstruction of each index everyday is going to generate a huge amount of load on your database for no benefit and creates a number of opportunities to introduce errors.
Justin
-
I'm just having a bit of troubel get a correct join query - I thought it was an Inner Join, but I don't get the results I expect.
My table structure is:
Table: lodges
LodgeID (PK)
Lodge
etc.
Table: implemented application
NominationID (PK)
Category
LodgeID
Year
So I try to use this structure to replicate this page:
http://www.safariawards.com/nominees12/
That is to say a list of boxes for each category, they are appointed on.
The query I've tried looks like this:
SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. NominationID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge
But this product:
http://www.safariawards.com/nominees12/southernafrica.php
Its the right number of results, but not the list on the right of the boxes - for example British Airwways is not LodgeID 786
If anyone could help with the SQL right for what would be well appreciated.
That you join on the wrong column. Try this:
SELECT appointments. LodgeID, lodges. Lodge, applications. NominationID, applications. Lodges INNER JOIN applications category IT lodges. LodgeID = nominated. LodgeID WHERE category = "Best property of Safari in southern Africa" ORDER BY Lodge
-
Oracle 11G install on Win 7 with PL/SQL Developer Help Needed
Today is my first day with Oracle. I tried to install Ora11g since our network drive. I think that the installation went well. I also have installated PL/SQL Developer when I try to log in I got the following error see below.
---------------------------
PL/SQL Developer - (not connected)
---------------------------
Initialization error
SQL * Net not properly installed
OracleHomeKey: SOFTWARE\ORACLE
OracleHomeDir:
---------------------------
Ok
After I did some research on the Internet I found this solution "go to tools > Preferences > options manually set 'Oracle Home" in the folder "Library OIC" and ORACLE_HOME to file oci.dll is located in ORACLE_HOME/bin/oci.dll.
C:\app\user\product\11.2.0\Client_1\bin.dll < = I think it's my Oracle_Home
C:\app\user\product\11.2.0\client_1\bin\oci.dll < = is my OCI library.
When I apply a thse 2 ways I get the following error.
Initialization error
Could not load C:\app\user\product\11.2.0\client_1\bin.dll «»
OCIDLL to C:\app\user\product\11.2.0\client_1\bin.dll
LoadLibrary (C:\app\user\product\11.2.0\client_1\bin\.dll) returned 0
Can someone help me with this? /PL indicate which version of Win 7 - you need professional or superior - home versions are not taken in charge/certified, then things may or may not work as expected.
http://download.Oracle.com/docs/CD/E11882_01/install.112/e16773/reqs.htm#CHDHGGFE
HTH
Srini -
The following query works fine but I need to do the same thing but this time by using a join explicitly.
Select Departments.Deptnumber, Departments.name,
sum (quantity)
from SalesOrderItems, departments
where Departments.Deptnumber = SalesOrderItems.DeptNumber
Departments.Deptnumber group, Departments.name;
I tried
Select Departments.Deptnumber, Departments.name,
sum (quantity)
INNER JOIN SalesOrderItems ministries
ON Departments.Deptnumber = SalesOrderItems.DeptNumber
order of Departments.Deptnumber, Departments.name;
but get the error
ERROR at line 3:
ORA-00933: SQL not correctly completed command.
any help will be great thank you.What version of Oracle are you using?
SELECT * FROM v$version
ANSI style joins are available with version 9. ? and at the top
John
Maybe you are looking for
-
Why do I get messages cirtificate
you are about to replace how to identify thunderbirdThis site this site is trying to identify with the invalid informationcertificate belongs to another site that could indicate identity theft
-
HP Deskjet F2410: The printer does not print
I have a problem with my printer after reformatting my PC. Product name: HP Deskjet F2410 not Operating system: Microsoft Windows 7 (64-bit) Drivers and software are already installed. I have the new black and color ink cartridges When I send command
-
New MacBook 12 "power on problem
Hi, yesterday I turned on the power on my MacBook. The White Bar under slept for about 20 minutes at the end of race and no logo is not moved from there. So I Pushed power button 10 seconds to turn off. After that, no life! Tried everything. Reset th
-
I have deleted acidentally Dowloads from the dock. When I restored it I now get a huge page of each download I've ever done! How to get back to the simple short column of downloads?
-
Not updated by Labview VI Step property
Hello I am currently using 4 TS and LV 8.2 with Win7 Pro. I created a custom step which employs a lower Edit level. The lower Edit level name successfully a Labview vi, which allows the user to change the values. The intention is to copy the user val