sql server programming:
Hi, I have a table with Seq_No, City, and Customers' Disposition. CREATE TABLE CUSTOMER_DATA( Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, City varchar(10), Disposition varchar(10) ) INSERT INTO CUSTOMER_DATA VALUES('DEL','BUSY') INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') INSERT INTO CUSTOMER_DATA VALUES('MUM','BUSY') INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') INSERT INTO CUSTOMER_DATA VALUES('CAL','BUSY') INSERT INTO CUSTOMER_DATA VALUES('DEL','OTHER') INSERT INTO CUSTOMER_DATA VALUES('CAL','OTHER') INSERT INTO CUSTOMER_DATA VALUES('CHE','BUSY') INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') I want citywise analysis of datapoints in the following format. City, Count_of_Total_Data_Points_City_Wise, Count_of_Free_Disposition_Count_City_Wise How would I get third column count? Thanks Mukesh
Thanks again for the DLL. Next time post the desired result too. And Uri I think he needed this.. not sure though SELECT City, COUNT(City) as city_wise_something ,sum(case disposition when 'free' then 1 else 0 end) as count_free_blah_blah FROM CUSTOMER_DATA
forgive my ignorance.. but what does OP mean.. I can make out that its something to do with the one who asks the question..
Thanks, It is working Fine.
OP is short for "original poster" :) [quoted text, click to view] Omnibuzz wrote: > forgive my ignorance.. but what does OP mean.. > I can make out that its something to do with the one who asks the question..
Yep, I think you are both right [quoted text, click to view] "Omnibuzz" <Omnibuzz@discussions.microsoft.com> wrote in message news:EEF5EAC3-17CF-4D47-B0FA-CC6846B24A1A@microsoft.com... > Thanks again for the DLL. Next time post the desired result too. > And Uri I think he needed this.. not sure though > > > SELECT City, > COUNT(City) as city_wise_something ,sum(case disposition when 'free' then > 1 > else 0 end) as count_free_blah_blah > FROM CUSTOMER_DATA > GROUP BY City
Thank for posting DDL SELECT City, COUNT(City),COUNT(Disposition) FROM CUSTOMER_DATA GROUP BY City If it does not help ,please provide a desired result [quoted text, click to view] "mukesh" <cmukesh19@gmail.com> wrote in message news:1147928244.957965.271630@38g2000cwa.googlegroups.com... > Hi, > > I have a table with Seq_No, City, and Customers' Disposition. > > CREATE TABLE CUSTOMER_DATA( > Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, > City varchar(10), > Disposition varchar(10) > ) > > > INSERT INTO CUSTOMER_DATA VALUES('DEL','BUSY') > INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') > INSERT INTO CUSTOMER_DATA VALUES('MUM','BUSY') > INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') > INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') > INSERT INTO CUSTOMER_DATA VALUES('CAL','BUSY') > INSERT INTO CUSTOMER_DATA VALUES('DEL','OTHER') > INSERT INTO CUSTOMER_DATA VALUES('CAL','OTHER') > INSERT INTO CUSTOMER_DATA VALUES('CHE','BUSY') > INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') > > I want citywise analysis of datapoints in the following format. > > City, Count_of_Total_Data_Points_City_Wise, > Count_of_Free_Disposition_Count_City_Wise > > How would I get third column count? > > Thanks > Mukesh >
I think the OP only wants to count the "Free"'s in the third column, something like: SELECT City, COUNT(City) AS [Total], SUM(CASE DISPOSITION WHEN 'FREE' THEN 1 ELSE 0 END) AS [Free] FROM CUSTOMER_DATA GROUP BY City [quoted text, click to view] Uri Dimant wrote: > Thank for posting DDL > SELECT City, > COUNT(City),COUNT(Disposition) > FROM CUSTOMER_DATA > GROUP BY City > > If it does not help ,please provide a desired result > > > > > "mukesh" <cmukesh19@gmail.com> wrote in message > news:1147928244.957965.271630@38g2000cwa.googlegroups.com... > >>Hi, >> >>I have a table with Seq_No, City, and Customers' Disposition. >> >>CREATE TABLE CUSTOMER_DATA( >>Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, >>City varchar(10), >>Disposition varchar(10) >>) >> >> >>INSERT INTO CUSTOMER_DATA VALUES('DEL','BUSY') >>INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') >>INSERT INTO CUSTOMER_DATA VALUES('MUM','BUSY') >>INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') >>INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') >>INSERT INTO CUSTOMER_DATA VALUES('CAL','BUSY') >>INSERT INTO CUSTOMER_DATA VALUES('DEL','OTHER') >>INSERT INTO CUSTOMER_DATA VALUES('CAL','OTHER') >>INSERT INTO CUSTOMER_DATA VALUES('CHE','BUSY') >>INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') >> >>I want citywise analysis of datapoints in the following format. >> >>City, Count_of_Total_Data_Points_City_Wise, >>Count_of_Free_Disposition_Count_City_Wise >> >>How would I get third column count? >> >>Thanks >>Mukesh >> > >
Hi, Suppose I am adding a new table named Disposition Master. CREATE TABLE DISPOSITION_MASTER( Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, Disposition varchar(10) UNIQUE, Status int ) INSERT INTO DISPOSITION_MASTER VALUES('BUSY',1) INSERT INTO DISPOSITION_MASTER VALUES('FREE',0) INSERT INTO DISPOSITION_MASTER VALUES('OTHER',0) INSERT INTO DISPOSITION_MASTER VALUES('CALLBACK',1) INSERT INTO DISPOSITION_MASTER VALUES('INTERESTED',1) Now in the third column I want count of dispositions from customer_data where disposition name is having status 1 in Disposition_Master table. Thanks Mukesh [quoted text, click to view] Baileys wrote: > I think the OP only wants to count the "Free"'s in the third column, > something like: > > SELECT > City, > COUNT(City) AS [Total], > SUM(CASE DISPOSITION WHEN 'FREE' THEN 1 ELSE 0 END) AS [Free] > FROM > CUSTOMER_DATA > GROUP BY > City > > > Uri Dimant wrote: > > Thank for posting DDL > > SELECT City, > > COUNT(City),COUNT(Disposition) > > FROM CUSTOMER_DATA > > GROUP BY City > > > > If it does not help ,please provide a desired result > > > > > > > > > > "mukesh" <cmukesh19@gmail.com> wrote in message > > news:1147928244.957965.271630@38g2000cwa.googlegroups.com... > > > >>Hi, > >> > >>I have a table with Seq_No, City, and Customers' Disposition. > >> > >>CREATE TABLE CUSTOMER_DATA( > >>Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, > >>City varchar(10), > >>Disposition varchar(10) > >>) > >> > >> > >>INSERT INTO CUSTOMER_DATA VALUES('DEL','BUSY') > >>INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') > >>INSERT INTO CUSTOMER_DATA VALUES('MUM','BUSY') > >>INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') > >>INSERT INTO CUSTOMER_DATA VALUES('MUM','FREE') > >>INSERT INTO CUSTOMER_DATA VALUES('CAL','BUSY') > >>INSERT INTO CUSTOMER_DATA VALUES('DEL','OTHER') > >>INSERT INTO CUSTOMER_DATA VALUES('CAL','OTHER') > >>INSERT INTO CUSTOMER_DATA VALUES('CHE','BUSY') > >>INSERT INTO CUSTOMER_DATA VALUES('CHE','FREE') > >> > >>I want citywise analysis of datapoints in the following format. > >> > >>City, Count_of_Total_Data_Points_City_Wise, > >>Count_of_Free_Disposition_Count_City_Wise > >> > >>How would I get third column count? > >> > >>Thanks > >>Mukesh > >> > > > > > >
Mukesh (cmukesh19@gmail.com) writes: [quoted text, click to view] > Suppose I am adding a new table named Disposition Master. > > CREATE TABLE DISPOSITION_MASTER( > Seq_No bigint IDENTITY(1,1) NOT NULL PRIMARY KEY, > Disposition varchar(10) UNIQUE, > Status int > )
What purpose would the Seq_No column serve? [quoted text, click to view] > INSERT INTO DISPOSITION_MASTER VALUES('BUSY',1) > INSERT INTO DISPOSITION_MASTER VALUES('FREE',0) > INSERT INTO DISPOSITION_MASTER VALUES('OTHER',0) > INSERT INTO DISPOSITION_MASTER VALUES('CALLBACK',1) > INSERT INTO DISPOSITION_MASTER VALUES('INTERESTED',1) > > > Now in the third column I want count of dispositions from customer_data > where disposition name is having status 1 in Disposition_Master table.
If I understand this correctly: SELECT c.City, d.Dispotision, COUNT(DISTINCT City), COUNT(*) FROM Customer_Data c JOIN Disposiiotn_master d ON c.Disposition = d.Disposition WHERE d.Status = 1 GROUP BY c.City, d.disposition -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at
Don't see what you're looking for? Try a search.
|