tauchai83 Posted January 23, 2007 Share Posted January 23, 2007 i trying to create a [color=red]new function to track the "good potential" customers who have purchase things more than 10 times through online.[/color] How to do a good sql statement tat will suit that need?my code is here:$strsql1 = "SELECT DISTINCT A.Cust_id, A.First_name, A.Last_name, A.Phone, A.Email, A.Address, B.Cust_id FROM customer A, orders B WHERE A.Cust_id=B.Cust_id";$result1 = mysql_query($strsql1);1 table contain customer particulars, another 1 is order table which has Cust_id as its Foreign Key... Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/ Share on other sites More sharing options...
worldworld Posted January 23, 2007 Share Posted January 23, 2007 I understand that your query is correct. :) Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-167065 Share on other sites More sharing options...
fenway Posted January 23, 2007 Share Posted January 23, 2007 I'm not sure I understand what you mean... but a proper JOIN, and no distinct would be better. Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-167454 Share on other sites More sharing options...
tauchai83 Posted January 24, 2007 Author Share Posted January 24, 2007 the query retrive what i want but how to echo/print only the customer's list that have purchased 10 times with my company? example...use count??? >10?? can give me idea? Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-168071 Share on other sites More sharing options...
fenway Posted January 24, 2007 Share Posted January 24, 2007 [code]SELECT A.Cust_id, A.First_name, A.Last_name, A.Phone, A.Email, A.Address, COUNT(B.Cust_id) AS cntFROM customer A LEFT JOIN orders B ON A.Cust_id=B.Cust_idHAVING cnt >10[/code] Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-168088 Share on other sites More sharing options...
tauchai83 Posted January 25, 2007 Author Share Posted January 25, 2007 fenway,the sql tat u wrote does not work at all...nothing come out and error msg display no record found!....i have revised my table and it seem logic...just nit a complete or maybe i would say advanced sql statement to retrieve it from DB....any more idea? i understood what u wrote....is good...but does not work....anymore idea?? :).. thanks a lot!-chai- Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-168858 Share on other sites More sharing options...
fenway Posted January 25, 2007 Share Posted January 25, 2007 Sorry, I missed a group by... Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169050 Share on other sites More sharing options...
tauchai83 Posted January 25, 2007 Author Share Posted January 25, 2007 GROUP By what? the cust_id??? Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169352 Share on other sites More sharing options...
tauchai83 Posted January 26, 2007 Author Share Posted January 26, 2007 Ok..solve...anyhow...i did not use Left Join...just customer A, orders B and add Group By Cust_id...thanks a lot fenway...u are really mysql super guru who can give idea...thanks ya...i have one new query problem which not sure u can help...how to select an product that have expire?I have one table called product: pd_id, pd_qty, pd_name, pd_description,[color=red]Expire_Date [/color] field.this expire date i put as [color=red]VarChar[/color] in the format of dd-mm-yyyy..eg...27-01-2007i want to retrieve ALL expired item from this table..the following is my code tat did not work...$day = date("d");$month = date("m");$year = date("Y");$today= $year.'-'.$month.'-'.$day;$sql = "SELECT * from product WHERE 'strtotime(Expire_Date)<strtotime($today)'";$result1 = mysql_query($sql);i have try many ways....how to solve this? should i put the Expire_Date as date format instead Varchar?plz help..thank you for ur time...i try use strtotime to compare it....i think that's wrong..but how can i solve this prob? Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169562 Share on other sites More sharing options...
fenway Posted January 26, 2007 Share Posted January 26, 2007 I simply suggested LEFT JOIN in case you wanted to every get a count() of zero.First, regarding your new query, you don't need any of that fancy PHP date stuff... use CURRENT_DATE(), a MySQL date function. Then, just use normal comparison operators:SELECT * FROM product WHERE ExpireDate < CURRENT_DATE() Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169604 Share on other sites More sharing options...
tauchai83 Posted January 26, 2007 Author Share Posted January 26, 2007 so the Expire_Date i should put as "date" or "varchar" to compare? Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169624 Share on other sites More sharing options...
tauchai83 Posted January 26, 2007 Author Share Posted January 26, 2007 hehe..done...fenway..thanks a lot! u know what is si fu? superguru!...thanks.... Link to comment https://forums.phpfreaks.com/topic/35339-solved-query-help/#findComment-169627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.