SQL & PL/SQL :: Find Count Of Customers Which Are In Same Campaign
Apr 16, 2013
The communication table has around 1 billion rows which is partitioned by a date column which is not used in the query. The hierarchy table has only 10000 rows. rewrite the query if its possible.Its trying to find the count of customers[distinct] which are in the same campaign.
select h.brand_cd, h.campaign_name, h.campaign_start_dt, h.campaign_name,h.campaign_desc,h.subject, count(distinct cc.customer_id)
from communication cc,hierarchy h
where cc.campaign_hierarchy_id = h.campaign_hierarchy_id
and h.brand_cd in ('ABY','AYO')
AND H.CAMPAIGN_OWNER = 'WONDER'
and h.campaign_start_dt >'1-JUL-2011'
group by h.brand_cd, h.campaign_name, h.campaign_start_dt, h.campaign_desc,h.subject;
View 1 Replies
ADVERTISEMENT
Mar 2, 2010
I want to get a list of vendors based on country and campaign.I first get all vendors based on country then i subtract the vendors i shouldn´t see (the vendors i should not see minus those i should see).Below you see my query - is there a better way to get the same result?
3 tables
vendor - vendorInformation
vendorcountry_spec - A vendor can be located in different countries with different information.
vendorcountry_campaign - In a country there are different campaigns. If there is a row in this table, only those with the campaignID should see the vendor else everyone in that country.
The query:
SELECT v.vendorID
FROM vendor v, vendorcountry_spec vs
WHERE v.VENDORID = vs.VENDORID AND v.status = 'A'
AND vs.STATUS = 'A' AND vs.ISCORPORATE = 1
AND v.ISNOTHIGHLIGHTED = -1 AND vs.COUNTRYCODE = 'SE'
GROUP BY v.sortNr, v.vendorID
[code]....
View 4 Replies
View Related
May 6, 2009
I have written a script to get count of each tables of a schema.
DECLARE CURSOR c1 IS
select distinct table_name from all_tab_columns where OWNER='PLAY';
countrows NUMBER;
[Code].....
View 1 Replies
View Related
Mar 31, 2009
SQL> select count(*) from tab;
COUNT(*)
----------
63
I need to find out how many rows in each table.I've tried with cursor.
View 9 Replies
View Related
Apr 16, 2010
from the below string i want to find the count of the "<-" using a single query.
string is "aaaa<-bbbb<-ccccc<-ddddd<-eeeeee<-ffffff<-"
If not the query, pointer on using SQL functions.
View 3 Replies
View Related
Sep 26, 2012
I want to find the Pass rate for each term by adding up the grades.
PASS = HD/D/PASS FAIL = FAIL and Z means no mark has been recieved yet so i do not want to include it in the calculation.
CREATE TABLE DAN_GR
(ID VARCHAR2(8),
TERM VARCHAR2(8),
GRADE VARCHAR2(8),
SUBJECT VARCHAR2 (8),
STAT VARCHAR2 (8))
[Code]....
So term 1201 has 1 Pass 1 Fail and a Z (which is not counted) so pass rate is 50%
term 1202 has has 1 Pass only so the pass rate is 100%
term 1203 has 1 Fail so pass rate is 0%
term 1204 has 1 Pass and 2 Fails and i dont count the 3rd fail because the stat is 'APSENT' i only want to count the once where stat is 'PRESENT'
WANT:
COUNT TERM PASS RATE
3 1201 50%
1 1202 100%
1 1203 0%
3 1204 33%
I am using:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
View 4 Replies
View Related
May 24, 2008
I have three tables,let's say
table stores
sid | store_name
1 | one
2 | two
3 | three
table products
pid | sid | p_name
1 | 2 | pone
2 | 2 | ptwo
3 | 3 | pthree
table sales
said | sid | pid
1 | 2 | 1
2 | 3 | 1
3 | 2 | 2
4 | 1 | 3
5 | 2 | 2
6 | 3 | 2
7 | 3 | 2
and i want display the product that sells best in every store. I try to group by multiple columns counting how many times each product was sold in every store, but don't know how to select the one which was best sold (maximal number of times)
View 5 Replies
View Related
Jun 29, 2010
Need a query to find the count of presence of delimiter "," in column VAL for below mentioned table.
Table:
CREATE TABLE N_B_S_1
(
NUM NUMBER,
VAL VARCHAR2(20)
)
Data:
INSERT INTO N_B_S_1 VALUES(1,'A,B,C');
INSERT INTO N_B_S_1 VALUES(2,'D');
INSERT INTO N_B_S_1 VALUES(3,'ER,NF,G,H,XK');
INSERT INTO N_B_S_1 VALUES(4,'LQW,MBV');
INSERT INTO N_B_S_1 VALUES(5,'KS,YJ,WE,RQ,PM');
COMMIT;
Required output:
num, count of delimiters
===== ===========
1 2
2 1
3 4
4 2
5 4
View 5 Replies
View Related
Nov 5, 2013
I need the number of unique customers which buy product "7" per month.
Product Customer Date
7 A 22.07.2013
7 A 22.07.2013
7 A 22.07.2013
1 B 23.10.2013
1 A 20.07.2013
7 C 23.07.2013
7 C 23.07.2013
11 D 30.07.2013
1 C 30.10.2013
1 E 01.11.2013
11 C 04.11.2013
My first move: SELECT Product, Customer, Date FROM TABLE WHERE Product = '7' AND Date BETWEEN StartDate AND EndDate
But i need the unique customer.
View 11 Replies
View Related
Sep 14, 2012
I am soon engaging in a project where we will deploy three triggers to each table in a customers live database. One each for Inserts,Updates and deletes.
These triggers write or update a row in a separate table on a different schema.
We have experienced locking issues on these tables previously with SQL Server. Are there settings we can look at to improve performance?
View 2 Replies
View Related
Jul 17, 2013
what I want my code to do is display the customers who live in either Georgia or Florida who recently placed an order totaling more than $80.
My code so far:
SELECT LastName, FirstName, SUM(Retail * Quantity) AS Total
From CUSTOMERS, ORDERS, ORDERITEMS, BOOKS
Where (State = 'FL' OR State = 'GA')
Group by customers.customer# Having SUM(Retail * Quantity) > 80.00;
How would I get this to work?
View 4 Replies
View Related
May 21, 2010
how do I count a list of number value eg 1,1,1,1,3,3,6,4 and find the one with maximum number which is 1
View 5 Replies
View Related
Jan 6, 2012
I've 2 table with below colums
Create table rent (customer_id number(10),
doc_num varchar2(20)
);
Create table doc_id (doc_num varchar2(20));
Insert into rent(customer_id) values (1);
Insert into rent(customer_id) values (2);
Insert into rent(customer_id) values (3);
Insert into rent(customer_id) values (4);
[code]...
Now my requirement is i need to assign doc_num from doc_id table to 4 customers in rent table randomly. I mean update doc_num in rent table from doc_id table randomly. how to write update statement.
View 8 Replies
View Related
Nov 16, 2009
When we execute select count(*) from table_name it returns the number of rows.
What does count(1) do? What does 1 signifies over here? Is this same as count(*) as it gives the same result on execution?
View 13 Replies
View Related
Nov 24, 2011
difference between count(1) and count(*). As i know count(*) will give number of rows irrespective of null and count(1) will not count the null.My Oracle version is 10 g.
SQL> select * from t1;
A B C
---------- -------------------- --------------------
1 2 3
2
5
SQL> select rownum,a.* from t1 a;
ROWNUM A B C
---------- ---------- -------------------- --------------------
1 1 2 3
2 2
3 5
4
[code]....
View 3 Replies
View Related
May 24, 2010
I have the folloiwng two queries:
Query_1: select count(*) yy from table1;
Query_2: select count(*) zz from table2;
I need to compute the following:
var:=(yy/zz)*100
How can I achieve this in a single query?
View 3 Replies
View Related
Mar 23, 2013
I'm using this code, and it performs fine, but I'm wondering if there is a more elegant way to do it--maybe with "ROLLBACK". Basically (as you can see) I need to get a normal count for each group but also for each group take a percentage of the total count (so all groups pct adds up to 100 (oh yeah, don't test for zero below, but just a test... )
select
c.Event,
c.code,
count(1) as calls,
total.total_count,
count(1) / total.total_count * 100 as pct_of_total
from
table1 c
[Code]....
[Edit MC: add code tags, do it yourself next time]
View 4 Replies
View Related
Feb 28, 2013
I have one tbale like
TABLE A with columns bu_code and bu_cty
bu_code bu_cty
12 ES
12 ES
13 AP
13 AP
so now i want to know the count for bu_code
like my output shd be
bu_code(12) ---count is 2
bu_code(13)------count is 13
View 4 Replies
View Related
Mar 4, 2009
I have this query and I want to get the COUNT:
SELECT first_np AS n_p FROM dvc
UNION
SELECT second_np AS n_p FROM dvc
UNION
SELECT n_p FROM dc;
This returns one column which is the n_p; how do I get the count of n_p?
View 2 Replies
View Related
Oct 9, 2008
say there is astring "mumbojumbo "i need the count of given string in it
ex:when o is given count shuld be 2 when m is given count shuld be 3
is there any pre defined function for counting a given string ...
View 2 Replies
View Related
Mar 26, 2012
I have a table with the following fields :
RGS_CAN_PERIOD NUMBER(4)
RGS_ID_ELECTOR NUMBER(
FBD_NID VARCHAR2(14)
RGS_SURNAME VARCHAR2(40)
RGS_O_NAME VARCHAR2(40)
RGS_ALIAS VARCHAR2(30)
RGS_ADDR VARCHAR2(75)
RGS_ID_REG_AREA VARCHAR2(3)
[Code]..
I need a report as hereunder :
Reg. Area Age <=19 20 <= Age <= 24 25 <=Age <= 29 Total No. of Voters
xxxx 10 15 7 32
yyyy 5 7 3 15
I have work out a script but the age is not in a range
select *
FROM (select rgs_id_reg_area,
count(decode(fbd_age,19,fbd_age)) Age19,
count(decode(fbd_age,20,fbd_age)) Age20
FROM rubyvoterstat where vote ='Y'
GROUP by rgs_id_reg_area)
order by rgs_id_reg_area
View 1 Replies
View Related
Feb 14, 2012
I have the following table with insert below.
CREATE TABLE ATTENDANCE
(
"REG_NO" NUMBER(7,0),
"COURSE_SEQ_NO" NUMBER(4,0),
"SECTION" VARCHAR2(1 BYTE),
"SEMESTER_CODE" NUMBER(1,0),
[code]...
How can I have the following output?
course_seq_nosectiontotal_recordscount_1count_0
322X20137
I tried decode but it could not find its way
View 9 Replies
View Related
Mar 10, 2010
I am running this query but am not getting data that is correct.
SELECT a.prod_id, a.prod_name, a.artist_name, COUNT(*)
FROM po_my_purchase_tb a, cm_track_tb b
WHERE a.prod_id = b.prod_id and b.GNR_CD = 'GR000017' AND a.purchase_date > '10-FEB-10' AND ROWNUM<50
GROUP BY a.prod_id, a.prod_name, a.artist_name, a.buy_seq
ORDER BY COUNT(*) desc
View 8 Replies
View Related
Mar 7, 2013
I need suing group by for getting count.I have a table with columns below
SYS_AUDIT_IDSYS_AUDIT_PROG_IDPROG_FINDING_ID_COUNT
178921652
178921641
178921631
179321521
179321511
179321501
179321491
179321461
I want to count number of SYS_AUDIT_PROG_ID for each audit and count of PROG_FINDING_ID_COUNT
I want to get
1789 3 4
I tried this query but this is not working
[code]select sys_audit_id ,count (sys_audit_prog_id), count(prog_finding_id_count) from
my_table sub
group by sys_audit_id [/code]
View 2 Replies
View Related
Dec 13, 2012
I need to get an accumulated value for a count. E.g. The table has purchased date, purchased item, purchased item type. The count of purchased item groyup by purchased type on every purchased date. Now, we got the count value (purchased item). But, I want the accumulated count value on every purchased date. So that I will get that how many items has been purchased on a particular date.
View 5 Replies
View Related
Nov 16, 2011
I pulled in 1121 SSN's into a table and am using that table as the basis for returning data from other tables...including how many documents a user has in their folder.
My query; however, is only returning 655 rows...it is returning only those rows that have documents in their folders. I want to return ALL rows...WHETHER OR NOT THEY HAVE A DOCUMENT COUNT (count(*)). How can I get all 1,121 rows to return? I would like the output to look like:
SSN LOCATION EMP_STATUS FOL_STATUS COUNT(*)
-- For those folders containing documents:
XXX-XX-XXXX WHATEVER WHATEVER WHATEVER 12
-- For those folders containing 0 documents:
XXX-XX-XXXX WHATEVER WHATEVER WHATEVER NULL
Here is the query in it's current state:
-- Get User/Folder/Doc Count Information
SELECT b.ssn,
b.location,
b.emp_status,
c.fol_status,
COUNT (*)
[Code]....
So again, my problem here is that...not all FOLDERS contain DOCUMENTS...but I still want the folder data lised...I just need it listed with either a zero count (0), or a NULL in the COUNT(*) column.
I'm trying the various joins, but none of them seem to be working.
I've tried the old 8i (+) join as follows:
AND c.fol_id = d.doc_fol_id(+)
I've tried the inner join:
AND c.fol_id(+) = d.doc_fol_id
...and I've tried the 9i method (left outer and full outer) using the following types of notations:
folder c full outer join documend d on c.fol_id = d.doc_fol_id
...so far, no luck. I'm still having only 655 rows returned (the 655 are those folders that HAVE document count > 0. Any folder that has zero documents in the document table just aren't being returned in the query.)
View 9 Replies
View Related
Jun 14, 2007
we're having a few tables which queries about 10.000 articles. As we don't show them all at once we are using pagination and use the rownum to show only a limited number of the results.
Now as these queries are pretty complex we have to optimize them and since we use pagination we have to call our query twice (first we make a count(*) and then we call the small resultset of a few rows). Ofcourse we are looking for a solution to call it only once and still use the pagination. We could load the whole resultset of 10.000 results and let java show only a few but that makes our line between the oracle and webserver pretty heavy. Is there a way to call the total number of results and give back only a small resultset just in one query?
View 1 Replies
View Related
Sep 24, 2012
I have a table employee
name title
A manager
B sales
c manager
D engineer
E marketing
I want to know how many people has title as manager?
the answer is 2 how to do the count, I can't do count(title), right ?
View 2 Replies
View Related
Jul 13, 2011
SQL> select * from test11;
A B C
--------------------------------------
AA 123
BB 100 200
CC 300
AA
How to count no null in the above table
View 9 Replies
View Related
May 3, 2013
oracle SQL,
Student(unique) has five races in a table
I need a select statement with student_id - 1 column
I need to count the number columns with values 'Yes' in them
the columns are race1,race2,race3,race4,race5 for a single row --- this should be 2 ndcolumn
The 3rd column should contain the max of the race having 'yes' in them
i.e if race1 and race 3 have values'yes' in them i need 3 in the next column, - 3rd column
View 5 Replies
View Related