This will group the results by call center and then sum it for you. In regards to your question about getting the sum for all centers.You need to add a GROUP BY in your SQL statement. Not only is it less code but you know for a fact that it works. Select cost_center_name, qualified_amount Your Large SQL statement would be in the database as. If this was a view then this is what you get. I admit this could be my lack of knowledge. That is pretty slow considering? I might need to index some of the columns, but I am concerned about the lack of "control" using inline-SQL statements. Running through my inline Query Statement as it stands runs about 9 seconds add this is on my local server. I figure they could both share a single SP. Since I need to do this twice, once for the spreadsheets and once for the pdf report. My thought right now is to use a SP to build about 20 "temporary tables", which pretty much mimic the data needed in the final spreadsheet. At least with stored procedure I can use "FOR each". Why is this only running on one row? I thought this would go through each cost center and do the same thing. There is a cost_center called test, but there are about 30 other ones too. What I get when i run this is:Ĭost_center_name qualified_percent qualified_amount I'd like to sum w2_wages in the employees table for each of the cost centers that appear in the cost_center table. SELECT cc.cost_center_name, cc.qualified_percent, SUM(e.w2_wages) as qualified_amount I am just not sure what a view gets me? I have this example query (one of about 20): It can help you cut down on coding as well (because most of the query will be in the database). My plan is to create a stored procedure to increase speed and give me better control.Īlso don't forget about database views. So having 29 queries is really slowing down my system. Each row has a userid and campaign that is used for filtering. I have a bunch of these queries because there are so many tables. Which pulls all records from left table plus the records that equal to it in the right table. RE: SQL Join is failing - php_rocs - richb201, #1064 - You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT OUTER JOIN ON cost_center ON cc.cost_center_name=e.department LIMIT 0, 25' at line 5 LEFT OUTER JOIN cost_center ON cc.cost_center_name=e.department WHERE e.email='$email' AND e.campaign='$campaign'ĪND cc.email='$email' AND cc.campaign='$campaign' SELECT cc.cost_center_name, cc.qualified_percent, cc.qualified_percent as qualified_amount +- Thread: SQL Join is failing ( /showthread.php?tid=77301)
0 Comments
Leave a Reply. |