
SQL Query Rewrite
- or -
Post a project like this4982
$$
- Posted:
- Proposals: 8
- Remote
- #183259
- Awarded
WORDPRESS Specialist, CMS, Responsive & Mobile Designs, PHP Frameworks & API's , ECOMMERCE
Php Developer ,Web Developer , CMS , MYSql, Xhtml, CSS, AjaX, Javascript,Jquery,Java,visual basic,website developer
79651318233357291294519324487361084356508365472
Description
Experience Level: Intermediate
I need to create a query that will return results based on set criteria and then basically count the number of results it returns to input into a graph.
This is what I have that works, but is sometimes slow,
SELECT MAX(complete_date) FROM projects_questions
INNER JOIN report_answers ON report_answers.question_id = projects_questions.id
INNER JOIN projects_reports ON projects_reports.visit_id = report_answers.visit_id
INNER JOIN retailers_addresses ON retailers_addresses.id = projects_reports.store_id
WHERE
projects_questions.question_text = '".$data_questions['question_text']."'
AND
projects_questions.attr_id = '".$data['id']."'
AND
answer = '$ans'
AND projects_reports.complete='1'
GROUP BY projects_reports.store_id;";
This will basically return any rows that have the answer defined by $ans AND the survey is complete AND belongs $attr_id group AND question_text matching.
We basically visit stores to get survey feedback, so the above needs to ensure only the last entry for a store is shown.
I also need to add a sub query to ensure that the store was asked the question (some asked in some stores and not in others)
I tried to achieve this using the below within the WHERE clause, it seems to work possibly but is extremely slow.
retailers_addresses.id IN (SELECT store_attribute_assign.attr_id FROM store_attribute_assign WHERE store_attribute_assign.attr_id = '".$data['id']."')
Im looking for someone to rewrite or even split if it will work out faster.
I need this doing ASAP!!!
This is what I have that works, but is sometimes slow,
SELECT MAX(complete_date) FROM projects_questions
INNER JOIN report_answers ON report_answers.question_id = projects_questions.id
INNER JOIN projects_reports ON projects_reports.visit_id = report_answers.visit_id
INNER JOIN retailers_addresses ON retailers_addresses.id = projects_reports.store_id
WHERE
projects_questions.question_text = '".$data_questions['question_text']."'
AND
projects_questions.attr_id = '".$data['id']."'
AND
answer = '$ans'
AND projects_reports.complete='1'
GROUP BY projects_reports.store_id;";
This will basically return any rows that have the answer defined by $ans AND the survey is complete AND belongs $attr_id group AND question_text matching.
We basically visit stores to get survey feedback, so the above needs to ensure only the last entry for a store is shown.
I also need to add a sub query to ensure that the store was asked the question (some asked in some stores and not in others)
I tried to achieve this using the below within the WHERE clause, it seems to work possibly but is extremely slow.
retailers_addresses.id IN (SELECT store_attribute_assign.attr_id FROM store_attribute_assign WHERE store_attribute_assign.attr_id = '".$data['id']."')
Im looking for someone to rewrite or even split if it will work out faster.
I need this doing ASAP!!!
William S.
100% (11)Projects Completed
17
Freelancers worked with
17
Projects awarded
56%
Last project
7 Feb 2019
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies