![]() LEFT JOIN o ON c.coID = o.orCompanyIDĪnother question is, what to group by. LEFT JOIN AccountHandler a ON c.coCSR = a.ahID I think you put it before WHERE, but in fact it should go after it (and before ORDER BY): SELECTĪ.ahFirstName + ' ' + a.ahLastName AS CSRName, The most likely reason why your attempt at grouping failed might be because you put GROUP BY in the wrong place. Therefore you need to group by companies. You seem to be aggregating data by companies. Better still, can you help me understand why it doesn't work at the moment? :)įor one thing, your query is probably missing FROM Company, but that might somehow have been lost when you were writing your post. I have to admit, I don't yet understand the logic and syntax of anything but the most basic SQL commands, I'm just trying to apply what I've seen used before, and it's not working. If I change the WHERE to HAVING because of the aggregate functions, I get errors telling me to remove each of the other column names that aren't contained in either an aggregate function or the GROUP BY clause. If I use GROUP BY coID, I get Incorrect syntax near the keyword 'WHERE'. The error is: Column name 'AccountHandler.ahLastName' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause. Here is the query I have tried, which produces an error: SELECT coID, coName, ahFirstName+' '+ahLastName AS CSRName, COUNT(orID) AS numOrders, SUM(orValue) AS totalRevenue ![]() Now what I need to produce is output structured as follows: Company | Account handler | No. ![]() The coCSR field is a numeric ID which relates to the account handler table: AccountHandler ![]() Let's say I have a table of companies: Company ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |