tjverge Posted February 7, 2011 Share Posted February 7, 2011 Hi, I have a SQL Query of SELECT sum('chiralstuctors') FROM `pi` WHERE `pilot` = 'Test' AND 'pidate' BETWEEN '2011-2-1' AND '2011-2-7' it should return 3000 but it keeps coming back Null, any ideas how to get the right data to return? Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/ Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 Try BETWEEN '2011-02-01' AND '2011-02-07' Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171152 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 thanks for the idea but it still came back NULL Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171154 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 Change the single quotes around pidate to `backticks` . . . Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171156 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 changed, still same result I tried with both 2011-1-2 and 2011-01-02 Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171158 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 What is the data type of the pidate field? Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171159 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 date Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171161 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 Have you tried executing the query in phpMyAdmin to see what it returns? I don't see any reason it shouldn't work unless there are no matching records. Post the code you're using to run the query and display the results. Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171162 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 SELECT sum('chiralstuctors') FROM `pi` WHERE `pilot` = 'Test' AND `pidate` BETWEEN '2011-01-02' AND '2011-07-02'  Results:0  But in my table I have:3000 under column chiralstuctors  Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171164 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 What is the data type of the chiralstructors field, and are you trying to get a count of the number of records returned? Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171165 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 data type is bigint, and no all I did was run the query in phpmyadmin, I'm just looking for a sum of all the numbers in that column. Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171166 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 I put together a php code for it and it finds 1 record that way. $sql = "SELECT sum('chiralstuctors') FROM `pi` WHERE `pilot` = 'Test' AND `pidate` BETWEEN '2011-2-1' AND '2011-2-7'"; $results= mysql_query($sql) or die(mysql_error()); $numrows = mysql_num_rows($results); Echo $numrows. "Records found";  Is that what you meant by finding the number of records returned? Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171169 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 I was just making sure you weren't mistakenly using SUM() when you intended to use COUNT(); that happens fairly frequently.  So we're on the same page here, The query executes without error in phpMyAdmin, and returns a value of 0 for sum(`chiralstructors`), correct? How many results does the query show it returns if you change it to read  SELECT `chiralstructors` FROM `pi` . . . instead of using the SUM function? Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171176 Share on other sites More sharing options...
tjverge Posted February 7, 2011 Author Share Posted February 7, 2011 It's solved thanks for you help you had the right idea with changing pidate to use ` chiralstuctors needed them too, thank you again for working with me on this Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171177 Share on other sites More sharing options...
Pikachu2000 Posted February 7, 2011 Share Posted February 7, 2011 Ah, hell. I didn't even notice that one. Getting old, eyes going bad. That's my story and I'm sticking to it. Quote Link to comment https://forums.phpfreaks.com/topic/226994-between-not-returning-expected-results/#findComment-1171190 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.