Jump to content

jcombs_31

Staff Alumni
  • Posts

    2,064
  • Joined

  • Last visited

Posts posted by jcombs_31

  1. Can you please show your table descriptions. 

     

    E.g., "Describe table users", "Describe table pages"

     

    FYI, you can use the bake console utility to create your basic models, controllers, views as long as your DB uses the cake conventions.

  2. it is suggested that you remove the where clause and include the conditional lookup within the join, yet you say that "adding" it to the where clause would return "all records".  That makes no sense.  if you added that SQL to your where clause you would get nothing but errors.  On top of that, how does adding conditions to a where clause cause all records to be returned (with the obvious exception of a stupid OR stuck in for a giggle)? 

     

    Your reply is nonsensical from start to finnish, so in answer - all of it.

     

    The whole point in the left join is to return all records from the left table regardless of a match on the right table.  I want to query only specific employees, not all employees. I've tried adding the to the ON, and I ALWAYS get all employees.

     

    My understanding is that you'd use the ON clause for any condition that is not on the left table.

  3. I would suggest removing the where an placing it in the join:

     

    I have had a similar problem, and doing that has worked for me.

     

    SELECT WEEK(Review.created)                               AS Week,
           CONCAT(Employee.firstname, ' ', Employee.lastname) AS Name,
           AVG(Rating.scale)                                  AS Average
    FROM   employees Employee
           LEFT JOIN reviews Review
             ON (Employee.id = Review.reviewee_id and Employee.id IN ( 71, 72 ))
           LEFT JOIN ratings AS Rating
             ON Rating.id = Review.rating_id
    GROUP  BY WEEK(Review.created),
              Employee.id
    ORDER  BY WEEK(Review.created),
              Employee.id

     

    Adding the condition to the WHERE clause would cause ALL employees to be returned.  In the end I just ran a query for each employee and combined them into a single array to use for my line graph.  There is not much overhead as generally only a few employees will be selected and I can guarantee my results this way.

     

    :wtf:

     

    Which part?

  4. I would suggest removing the where an placing it in the join:

     

    I have had a similar problem, and doing that has worked for me.

     

    SELECT WEEK(Review.created)                               AS Week,
           CONCAT(Employee.firstname, ' ', Employee.lastname) AS Name,
           AVG(Rating.scale)                                  AS Average
    FROM   employees Employee
           LEFT JOIN reviews Review
             ON (Employee.id = Review.reviewee_id and Employee.id IN ( 71, 72 ))
           LEFT JOIN ratings AS Rating
             ON Rating.id = Review.rating_id
    GROUP  BY WEEK(Review.created),
              Employee.id
    ORDER  BY WEEK(Review.created),
              Employee.id

     

    Adding the condition to the WHERE clause would cause ALL employees to be returned.  In the end I just ran a query for each employee and combined them into a single array to use for my line graph.  There is not much overhead as generally only a few employees will be selected and I can guarantee my results this way.

  5. but the employee field is NULL rather than the rating, which doesn't quite make sense

     

    make perfect sense to me... you are LEFT joining the calendar table with the reviews table, therefore if in any week there are no records in the table reviews your reviewee_id field is going to be NULL, hence the JOIN with the employees table will produce as result the employee name with NULL value.

     

    In your scenario the only way that your select is going to work and give the result that you are expecting is if for each week and for each employee there are at least 1 record in the table reviews with the field rating_id NULL, ZERO or any other value non-existent in the table ratings. The other probable solution is get only the data available with the SELECT, and post-process at display time (using some array and some logic to fill the missing records for a week).

     

    Thanks for the response.  I think in the end I'll have to use some application logic to get the results I want.  I was hoping I could do this with SQL alone, but based on my needs it seems that may not be possible.

  6. I've tried this

     

    SELECT WEEK(Calendar.datefield) AS Week, CONCAT(Employee.firstname, ' ', Employee.lastname) as Name, AVG(Rating.scale) as Average
    FROM calendar Calendar LEFT JOIN reviews Review ON WEEK(Calendar.datefield) = WEEK(Review.created)
    LEFT JOIN employees Employee ON Review.reviewee_id = Employee.id AND Employee.id IN (71, 72, 73)
    INNER JOIN ratings AS Rating on Rating.id = Review.rating_id
    WHERE Calendar.datefield BETWEEN '2011-09-01' AND '2011-12-31'
    GROUP BY Week, Employee.id
    ORDER BY Week, Employee.id
    

     

    which gets me close but the employee field is NULL rather than the rating, which doesn't quite make sense

  7. Hey guys.  I posted this on stack overflow but I'm still not getting exactly the results I want .  In the end I my just use PHP to put together an array for me, but I'd prefer to get this direct from the SQL query.

     

    Instead of typing it all out, here is the issue:  http://stackoverflow.com/questions/8647445/join-not-showing-all-rows

     

    I'm charting this with google charts.  I was reading this http://www.richnetapps.com/using-mysql-generate-daily-sales-reports-filled-gaps/ but I think my query is a bit more complex because of the groupings.  Any thoughts on the best way to go about this would be appreciated.

  8. I don' t quite follow, the form should have fields matching the fields in the database, so your model should be easy to set up validation based on the fields.  Perhaps the DB is not designed correctly.  Can you give a better example of exactly what you are trying to do? It sounds like you may need a many to many, but we'd need more details.

  9. jcombs you would help us to help you if you would post some more information than just those little pieces of information. Give us an ERD to look at and we can help you normalize it and/or provide advice/suggestions in how to improve the design.

     

    I don't have an ER to post, but what I'm looking to is a review for a call center type system. This system has a number of fields that the support person must fill out (A CRM for Technical Support).  There are a few tables that I need.

     

    [Employees]

    name, login, etc

     

    [Cases]

    Case number, details, etc

     

    [Review]

    Review Date

    Employee

    Case Number

    Case Summary <field in CRM>

    Problem Detail <field in CRM>

    Last Action <field in CRM>

    Notes

    Action

     

    An employee can own many cases and there can be multiple reviews done for each case over time.  Within the review the CRM fields will be graded with a list of actions to choose from.  This then leads to the actions table.  This was the list can be flexible and added to as needed rather than using something like an enum. 

     

    I like the concept of the many to many for fields <-> actions, but i'm struggling with the fact that a review will contain many fields from the CRM as well as additional data (Notes, Action Plan, etc).  There are more details/tables that I don't feel are relevant to this particular relation. 

     

    I thought about just handling this in PHP (just query the actions table to create the dropdowns for the input form and just use a varchar for the grading system in the table), but I didn't think this would be good design. 

     

    Does this make sense what I'm trying to accomplish?

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.