为什么我的复合查询不起作用?

时间:2023-01-12 00:06:32

I am having trouble getting the query I am working on to execute correctly. I have two tables and need the sum of certian columns in one table, but only need to sum numbers for certain rows based on flags that are set in another table. The query is as follows:

我无法获得正在执行的查询以正确执行。我有两个表,需要一个表中的certian列的总和,但只需要根据另一个表中设置的标志对某些行的数字求和。查询如下:

    SELECT (SUM(`jan_2014`) FROM `balances`  
             JOIN `locations`  AS `January 2014`, 
           (SUM(`feb_2014`) FROM `loan_balances`  
            JOIN `locations`  AS `February 2014`, 
           (SUM(`mar_2014`) FROM `loan_balances`  
             JOIN `locations`  AS `March 2014`,
   WHERE `loan_type` = 'payday' 
   AND `district_manager` = 'Melissa Lutz' 
   AND `store_name` = 'Marietta' 
   AND `fast_cash` = ‘0’ 
   AND `urgent_cash` = “0”

The numeric data is in table labeled "balances", and the flags for the rows I need is in table labeled "Locations", both in the same database labeled "Joe".

数字数据在表中标记为“balances”,我需要的行的标志位于标有“Locations”的表中,两者都在标记为“Joe”的同一数据库中。

1 个解决方案

#1


0  

I am grateful for the help, although as a REALLY new * user I made a mess of posting this question. The most helpful comment was that I need to study how to write queries. I did just that after posting this question and coming up short on the help I needed. I did come up with the answer. the query needed to look like this:

我很感激你的帮助,虽然作为一个真正的新*用户,我发布了这个问题。最有帮助的评论是我需要研究如何编写查询。我在发布这个问题之后就做到了这一点,并提供了我需要的帮助。我确实想出了答案。查询需要如下所示:

SELECT SUM(a.jan_2014), SUM(a.feb_2014), SUM(a.mar_2014), SUM(a.apr_2014) , SUM(a.may_2014) , SUM(a.jun_2014) FROM balances a INNER JOIN Locations b ON a.store_name=b.city WHERE product_type = 'pay' AND district_manager = 'Mel Lantz'  AND fast_cash = '0' AND urgent_cash = '1'

where I can check the fast_cash and urgent_cash flags conditionally in my code to determine which rows in the date columns I want the sum of.

我可以在我的代码中有条件地检查fast_cash和urgent_cash标志,以确定日期列中我想要总和的哪些行。

#1


0  

I am grateful for the help, although as a REALLY new * user I made a mess of posting this question. The most helpful comment was that I need to study how to write queries. I did just that after posting this question and coming up short on the help I needed. I did come up with the answer. the query needed to look like this:

我很感激你的帮助,虽然作为一个真正的新*用户,我发布了这个问题。最有帮助的评论是我需要研究如何编写查询。我在发布这个问题之后就做到了这一点,并提供了我需要的帮助。我确实想出了答案。查询需要如下所示:

SELECT SUM(a.jan_2014), SUM(a.feb_2014), SUM(a.mar_2014), SUM(a.apr_2014) , SUM(a.may_2014) , SUM(a.jun_2014) FROM balances a INNER JOIN Locations b ON a.store_name=b.city WHERE product_type = 'pay' AND district_manager = 'Mel Lantz'  AND fast_cash = '0' AND urgent_cash = '1'

where I can check the fast_cash and urgent_cash flags conditionally in my code to determine which rows in the date columns I want the sum of.

我可以在我的代码中有条件地检查fast_cash和urgent_cash标志,以确定日期列中我想要总和的哪些行。