beechy34 Posted March 20, 2009 Share Posted March 20, 2009 this is my code SELECT *from (SELECT COUNT(TOAC)as "callsNormNumbers" FROM TELCO_CALLS WHERE TOAC LIKE '01%') - (SELECT COUNT(TOAC)as "callsNormNumbers" FROM TELCO_CALLS WHERE TOAC not LIKE '01%'); this code is supposed to take away the total of all numbers that start with 01 from the TOAC column from the total of all the numbers that do not start with 01 from the same coumn, but it doesnt seem to work can someone help methankyou Link to comment Share on other sites More sharing options...
justsomeguy Posted March 20, 2009 Share Posted March 20, 2009 SELECT ((SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC LIKE '01%') - (SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC not LIKE '01%')) AS num Link to comment Share on other sites More sharing options...
beechy34 Posted March 21, 2009 Author Share Posted March 21, 2009 ok i tried it and had to change it a little to make give me an out put this is the code SELECT((SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC LIKE '01%') -(SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC not LIKE '01%')) as beechfrom TELCO_CALLS; the problem now is that it gives me 50 rows with each row showing the value of 30, all i want it 1 row showing the value of 30.can you or someone helpthankyou Link to comment Share on other sites More sharing options...
Synook Posted March 22, 2009 Share Posted March 22, 2009 Try SELECT DISTINCT ((SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC LIKE '01%') -(SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC not LIKE '01%')) as beechfrom TELCO_CALLS; or if only one distinct value will ever be returned just SELECT((SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC LIKE '01%') -(SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC not LIKE '01%')) as beechfrom TELCO_CALLS LIMIT 1; Link to comment Share on other sites More sharing options...
Stefano Posted March 24, 2009 Share Posted March 24, 2009 SELECT ((SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC LIKE '01%') - (SELECT COUNT(TOAC) FROM TELCO_CALLS WHERE TOAC not LIKE '01%')) AS numAs for me is not a count issue!!!The following works with mysql, if you use oracle use "decode" function in stead of "if()" function, anything else let me knowSELECT sum( num )FROM (SELECT if( TOAC LIKE '01%', +1, -1 ) AS numFROM TELCO_CALLS) AS aname regardsstefano De Boni Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.