inbowns Posted December 2, 2011 Share Posted December 2, 2011 I have a database which I was successfully able to pull data from and utilize but now I have a problem. I need to get data from a column that I have Yes or No in and I'm not sure to go about retriving this data. I basically need to count all the data that is listed as Yes. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/ Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 SELECT count(*) as yes_count FROM table_name WHERE column_yes_no = 'Yes' Should do it. Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/#findComment-1293580 Share on other sites More sharing options...
inbowns Posted December 2, 2011 Author Share Posted December 2, 2011 SELECT count(*) as yes_count FROM table_name WHERE column_yes_no = 'Yes' Should do it. Thank you for your reply I tired that and it works but I have other stuff that goes in the statement.Do you think you can help me clear that up also? $sql ="SELECT effdate, carrier, COUNT(carrier), SUM(employees), COUNT(employees),COUNT(migrate) FROM info WHERE effdate BETWEEN '$date_search_1' AND '$date_search_1' GROUP BY carrier" AND migrate = 'Yes' "; Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/#findComment-1293604 Share on other sites More sharing options...
premiso Posted December 2, 2011 Share Posted December 2, 2011 Your syntax is invalid... $sql ="SELECT effdate, carrier, COUNT(carrier), SUM(employees), COUNT(employees),COUNT(migrate) FROM info WHERE effdate BETWEEN '$date_search_1' AND '$date_search_1' AND migrate = 'Yes' GROUP BY carrier "; Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/#findComment-1293615 Share on other sites More sharing options...
inbowns Posted December 2, 2011 Author Share Posted December 2, 2011 Your syntax is invalid... $sql ="SELECT effdate, carrier, COUNT(carrier), SUM(employees), COUNT(employees),COUNT(migrate) FROM info WHERE effdate BETWEEN '$date_search_1' AND '$date_search_1' AND migrate = 'Yes' GROUP BY carrier "; Yes I understand because it doesn't run am I using too many AND's Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/#findComment-1293619 Share on other sites More sharing options...
Pikachu2000 Posted December 2, 2011 Share Posted December 2, 2011 Look at the BETWEEN parameters. You're using the same value for both of them. It may as well read 'BETWEEN 1 AND 1' . . . Quote Link to comment https://forums.phpfreaks.com/topic/252327-count-problem/#findComment-1293642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.