| | |
mysql logic
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
here is my situation:
i have a prepay online store and i advertised a contest to win a free code when buying at least 5 codes during 24.11-24.12 2008 period.
now this is my table:
i don't have a sql logic to : select all orders depending on date_purchased field which is in '2008-11-21 21:47:45' format, then calculate total number of orders for each of the customers in that period, depending on customers_id and orders_id i guess, then make a list of the customers that have the number of orders above or equal to 5 and finally randomly select one.
any ideas?
i have a prepay online store and i advertised a contest to win a free code when buying at least 5 codes during 24.11-24.12 2008 period.
now this is my table:
MySQL Syntax (Toggle Plain Text)
orders_id customers_id customers_name customers_company customers_street_address customers_suburb customers_city customers_postcode customers_state customers_country customers_telephone customers_email_address customers_address_format_id delivery_name delivery_company delivery_street_address delivery_suburb delivery_city delivery_postcode delivery_state delivery_country delivery_address_format_id billing_name billing_company billing_street_address billing_suburb billing_city billing_postcode billing_state billing_country billing_address_format_id payment_method cc_type cc_owner cc_number cc_expires last_modified date_purchased orders_status orders_date_finished currency currency_value
i don't have a sql logic to : select all orders depending on date_purchased field which is in '2008-11-21 21:47:45' format, then calculate total number of orders for each of the customers in that period, depending on customers_id and orders_id i guess, then make a list of the customers that have the number of orders above or equal to 5 and finally randomly select one.
any ideas?
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
... i have a prepay online store and i advertised a contest to win a free code when buying at least 5 codes during 24.11-24.12 2008 period. ... any ideas?
You need to use count() and group by. Something like this is kind-of close: MySQL Syntax (Toggle Plain Text)
SELECT count(id), id FROM table WHERE count(id)>4 AND (date_purchased>='2008-11-24' AND date_purchased<="2008-12-24") GROUP BY id ORDER BY count(id);
Last edited by Fest3er; Dec 25th, 2008 at 12:34 am.
![]() |
Similar Threads
- How to Connect MySQL from JSP Page (JSP)
- mysql+jsp (JSP)
- Regarding Mysql Query (MySQL)
- PHP/AJAX/Javascript/Mysql - Master - NO FREELANCE (Los Angeles) (Software Development Job Offers)
- java or mysql (Java)
- PHP/MySQL Developer (Web Development Job Offers)
- PHP Logic for Online Test (PHP)
- Creating a login page in PHP (PHP)
- How to compaire Stored Dates with System Date (PHP-MYSQL) (PHP)
- PHP/MySQL Developer, Brooklyn, NY | 65-75k (Web Development Job Offers)
Other Threads in the MySQL Forum
- Previous Thread: Error 2003: Can't connect to MySQL server on 'localhost' (99)
- Next Thread: Database set-up
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api aws bizspark breathalyzer changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





