我有一个SQL查询来从joomla网站内的幼儿园表格中获取信息,并做一些数学计算,以了解孩子父母应该每周支付多少钱,然后总结它以了解税收收据的数量。
当我只使用一个孩子时,我得到了正确的金额,但是只要我添加第二个,这些数字就不会与两个孩子相加。
以下是请求:
SELECT
SUM(t1.test1) AS t1,
SUM(t2.test2) AS t2
FROM
(
SELECT
(COUNT(josnh_facileforms_records.id) * sal1.salaire1) AS test1,
josnh_facileforms_subrecords.record
FROM josnh_facileforms_records,
josnh_facileforms_subrecords
LEFT JOIN
(
SELECT
LEFT(josnh_facileforms_subrecords.value, 5) AS salaire1,
josnh_facileforms_subrecords.record AS records1
FROM josnh_facileforms_records,
josnh_facileforms_subrecords
WHERE josnh_facileforms_records.user_id = [id]
AND josnh_facileforms_records.form = 24
AND josnh_facileforms_records.id = josnh_facileforms_subrecords.record
AND josnh_facileforms_subrecords.name LIKE 'enfant1'
GROUP BY
josnh_facileforms_subrecords.record
) AS sal1 ON sal1.records1 = josnh_facileforms_subrecords.record
WHERE josnh_facileforms_records.user_id = [id]
AND josnh_facileforms_records.form = 24
AND josnh_facileforms_records.id = josnh_facileforms_subrecords.record
AND josnh_facileforms_subrecords.name LIKE '%di1'
AND josnh_facileforms_subrecords.value = 'RG'
GROUP BY
josnh_facileforms_subrecords.record
) AS t1,
(
SELECT
(COUNT(josnh_facileforms_records.id) * sal2.salaire2) AS test2,
josnh_facileforms_subrecords.record
FROM josnh_facileforms_records,
josnh_facileforms_subrecords
LEFT JOIN
(
SELECT
LEFT(josnh_facileforms_subrecords.value, 5) AS salaire2,
josnh_facileforms_subrecords.record AS records2
FROM josnh_facileforms_records,
josnh_facileforms_subrecords
WHERE josnh_facileforms_records.user_id = [id]
AND josnh_facileforms_records.form = 24
AND josnh_facileforms_records.id = josnh_facileforms_subrecords.record
AND josnh_facileforms_subrecords.name LIKE 'enfant2'
GROUP BY
josnh_facileforms_subrecords.record
) AS sal2 ON sal2.records2 = josnh_facileforms_subrecords.record
WHERE josnh_facileforms_records.user_id = [id]
AND josnh_facileforms_records.form = 24
AND josnh_facileforms_records.id = josnh_facileforms_subrecords.record
AND josnh_facileforms_subrecords.name LIKE '%di2'
AND josnh_facileforms_subrecords.value = 'RG'
GROUP BY
josnh_facileforms_subrecords.record
) AS t2;
我可以再看看这个吗?
答案 0 :(得分:0)
好吧,这是一个新手问题我是如此专注于子查询,我忘了将FROM标签中的子查询与左标签链接。