-2
joomlaのWebサイト内の幼稚園の存在フォームから情報を取得するSQLクエリがあります。いくつかの数学を行い、子供の親が毎週支払うべき額を知ってから、税金領収書。複数レベルのサブクエリを使用したSqlクエリ
私はちょうど1人の子供を使うとき、私は正しい額を得るが、私が2番目の子供を追加するとすぐに、両方の子供に数字が足りない。ここで
はリクエストです:
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;
私はこの時二外観を得ることができますか?
私はこれがCodeReviewに行くべきだと思う... –
両方のために追加しなかったことはどういう意味ですか?あなたは '(sum(t1.test1)+ sum(t2.test2))をGrand_Totalとして使用しますか? – LONG
hum yes申し訳ありません、私は末尾の数字が加算されないことを意味します kid1 - > sum私のテストでは1人で189.66人で、正しい人数です。しかし、私がkid2の部分を追加すると、私は得る: kid1 = 379.3199999999999994 kid2 = 401.2999999999999995 変だね? – ddesbiens