我有不同的 sql,它返回不同的结果。我需要将它们全部按列获取。但我不知道该怎么做。有人可以帮我吗?下面是我的sql >>>
SELECT "one" AS value_1,
"two" AS value_2
SELECT "three" AS value_3,
"four" AS value_4
SELECT "five" AS value_5,
"six" AS value_6
主要查询 1>>>
SELECT -- lat.`group_info_id`, gi.`group_name`,
SUM(lat.`principal_outstanding`) AS principalOutstanding -- , SUM(lat.`accrued_interest`) AS interestReceivable, SUM(lat.`realizable_interest`) AS interestRealizable
-- , SUM(lat.`principal_outstanding`)+SUM(lat.`accrued_interest`)+SUM(lat.`realizable_interest`) AS loanDue, SUM(lat.`outstanding_balance`) AS totalLoanDue
FROM loan_account_transaction AS lat
INNER JOIN loan_account AS la ON (la.id = lat.`loan_account_id`)
LEFT JOIN group_info AS gi ON (gi.id = lat.`group_info_id`)
INNER JOIN
(
SELECT MAX(ilat.id) AS max_lat_id, ilat.loan_account_id
FROM loan_account_transaction AS ilat
WHERE ilat.`domain_status_id` = 1 AND ilat.`office_info_id` = (SELECT id FROM office_info WHERE office_code = 'UG500002')
AND ilat.`project_info_id` IN ('BI0000000000000000000004') AND ilat.transaction_date <= '2013-04-30'
GROUP BY ilat.loan_account_id
) AS tlat ON (tlat.loan_account_id = lat.`loan_account_id` AND tlat.max_lat_id = lat.id)
WHERE lat.`office_info_id` = (SELECT id FROM office_info WHERE office_code = 'UG500002')
AND lat.`project_info_id` IN ('BI0000000000000000000004')
AND lat.`loan_status_id` != 2 AND lat.`loan_status_id` != 7 AND la.`domain_status_id` = 1 AND lat.`domain_status_id` = 1
主查询 2 >>>
SELECT SUM(CASE WHEN la.loan_duration = 12 THEN 1 ELSE 0 END) AS total_count_40,
SUM(CASE WHEN la.loan_duration = 12 THEN IFNULL(la.disbursed_amount,0) ELSE 0 END) AS disbursed_amount_40,
SUM(CASE WHEN la.loan_duration = 6 THEN 1 ELSE 0 END) AS total_count_20,
SUM(CASE WHEN la.loan_duration = 6 THEN IFNULL(la.disbursed_amount,0) ELSE 0 END) AS disbursed_amount_20
FROM loan_account AS la
INNER JOIN member_info AS mi ON (la.disbursement_date <='2013-04-30'
AND la.project_info_id IN ('BI0000000000000000000004')
AND la.domain_status_id = 1 AND la.member_id=mi.id )
INNER JOIN office_info AS oi
ON( oi.id = 'BI0000000000000000000363' AND mi.branch_info_id = oi.id )
** 新的 >>>
SELECT COUNT(1), SUM(principal_outstanding)
FROM
(
/* Current Loan */
SELECT tempData.country_id,
tempData.project_info_id,
tempData.prodId,
tempData.loan_name,
tempData.office_info_id,
office_info.office_code,
office_info.office_name,
tempData.group_info_id,
group_info.group_code,
group_info.group_name,
missed_days,
SUM(tempData.principal_outstanding) AS principal_outstanding,
COUNT(DISTINCT member_id) AS borrower_count
FROM (
SELECT lat.country_id,lat.office_info_id,lat.project_info_id, lp.id AS prodId, lp.`loan_name`,
lat.group_info_id,
lat.principal_outstanding,la.member_id,
(CEIL(lat.overdue_amount/la.installment_amount) *
CASE WHEN lpp.policy_repayments_plan_id = 1 THEN
1
WHEN lpp.policy_repayments_plan_id = 2 THEN
7
WHEN lpp.policy_repayments_plan_id = 3 THEN
30
WHEN lpp.policy_repayments_plan_id = 4 THEN
365
END) AS missed_days
FROM loan_account_transaction AS lat
INNER JOIN loan_account AS la ON (la.id = lat.loan_account_id)
INNER JOIN loan_product AS lp ON (la.`product_info_id` = lp.`id`)
INNER JOIN loan_product_policy AS lpp ON(lpp.id = la.policy_info_id)
INNER JOIN (SELECT MAX(lat2.id) AS max_lat2_id,lat2.loan_account_id FROM loan_account_transaction AS lat2
WHERE lat2.transaction_date <= '2013-03-31' AND
lat2.domain_status_id = 1 AND
lat2.country_id IN (1) AND
lat2.office_info_id IN ('BI0000000000000000000363') AND
lat2.project_info_id IN ('BI0000000000000000000004')
GROUP BY lat2.loan_account_id
) AS temp ON lat.id = temp.max_lat2_id
WHERE (lat.loan_status_id= 1 OR lat.loan_status_id IS NULL)
) AS tempData
INNER JOIN office_info ON (office_info.id = tempData.office_info_id)
LEFT JOIN group_info ON (group_info.id = tempData.group_info_id)
WHERE missed_days > 30
GROUP BY
tempData.country_id,
tempData.office_info_id,
tempData.project_info_id,
tempData.prodId,
tempData.group_info_id,
missed_days
UNION
/* Late and NIBL Loan */
SELECT tempData.country_id,tempData.project_info_id,
tempData.prodId,
tempData.loan_name,
tempData.office_info_id,office_info.office_code,office_info.office_name,
tempData.group_info_id,group_info.group_code,group_info.group_name,
tempData.missed_days,SUM(tempData.principal_outstanding) AS principal_outstanding,
COUNT(DISTINCT tempData.member_id) AS borrower_count
FROM
(SELECT lat.country_id,lat.office_info_id,lat.project_info_id, lp.id AS prodId, lp.`loan_name`,
lat.group_info_id,
(CASE WHEN lat.loan_status_id = 3 THEN
(la.loan_duration*30) -- +(la.loan_duration*30/2)
WHEN lat.loan_status_id = 4 THEN
(la.loan_duration*30) -- *2
WHEN lat.loan_status_id = 5 THEN
(la.loan_duration*30) -- *2+7
WHEN lat.loan_status_id = 6 THEN
(la.loan_duration*30) -- *2+7
END) AS missed_days,
lat.principal_outstanding,la.member_id
FROM loan_account_transaction AS lat
INNER JOIN loan_account AS la ON (la.id = lat.loan_account_id)
INNER JOIN loan_product AS lp ON (la.`product_info_id` = lp.`id`)
INNER JOIN (SELECT MAX(lat2.id) AS max_lat2_id,lat2.loan_account_id FROM
loan_account_transaction AS lat2
WHERE lat2.transaction_date <= '2013-03-31' AND
lat2.domain_status_id = 1 AND
lat2.country_id IN (1) AND
lat2.office_info_id IN ('BI0000000000000000000363') AND
lat2.project_info_id IN ('BI0000000000000000000004')
GROUP BY lat2.loan_account_id
) AS temp ON lat.id = temp.max_lat2_id
WHERE (lat.loan_status_id != 2 AND lat.loan_status_id != 7 AND lat.loan_status_id = 1)
) AS tempData
INNER JOIN office_info ON (office_info.id = tempData.office_info_id)
LEFT JOIN group_info ON (group_info.id = tempData.group_info_id)
GROUP BY tempData.country_id,
tempData.office_info_id,
tempData.project_info_id,
tempData.prodId,
tempData.group_info_id,
missed_days
) AS t
GROUP BY t.prodId