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? 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' 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 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` . . . 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 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? 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 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. 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 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? 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. 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? 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? 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 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. 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
Archived
This topic is now archived and is closed to further replies.