SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
JOIN code
ON gl_accvouch.ccode = code.ccode
JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE gl_accvouch.ccode LIKE '5502%'
AND iyperiod LIKE '201411'
AND gl_accvouch.cdept_id LIKE '03%'
ORDER BY code.ccode_name
SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
JOIN code
ON gl_accvouch.ccode = code.ccode
JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE gl_accvouch.ccode LIKE '5501%'
AND iyperiod LIKE '201411'
AND gl_accvouch.cdept_id LIKE '02%'
ORDER BY code.ccode_name
执行2次语句比较麻烦。请问怎么能合并显示查询的结果?
------解决思路----------------------
SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
JOIN code
ON gl_accvouch.ccode = code.ccode
JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE ((gl_accvouch.ccode LIKE '5502%'
AND gl_accvouch.cdept_id LIKE '03%')
OR
(gl_accvouch.ccode LIKE '5501%'
AND gl_accvouch.cdept_id LIKE '02%'))
AND iyperiod LIKE '201411'
ORDER BY code.ccode_name
------解决思路----------------------
SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
INNER JOIN code
ON gl_accvouch.ccode = code.ccode
INNER JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE ((gl_accvouch.ccode LIKE '5502%'
AND gl_accvouch.cdept_id LIKE '03%')
OR
(gl_accvouch.ccode LIKE '5501%'
AND gl_accvouch.cdept_id LIKE '02%'))
AND iyperiod LIKE '201411'
ORDER BY code.ccode_name
------解决思路----------------------
select * from
(
SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
JOIN code
ON gl_accvouch.ccode = code.ccode
JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE gl_accvouch.ccode LIKE '5502%'
AND gl_accvouch.cdept_id LIKE '03%'
union all
SELECT iyperiod AS 会计期间,
csign AS 凭证类别,
ino_id AS 凭证编号,
code.ccode_name AS 科目名称,
gl_accvouch.md AS 借方金额,
gl_accvouch.mc AS 贷方金额,
gl_accvouch.cdigest AS 摘要,
gl_accvouch.cbill AS 制单人,
department.cdepname AS 部门名称
FROM gl_accvouch
JOIN code
ON gl_accvouch.ccode = code.ccode
JOIN department
ON department.cdepcode = gl_accvouch.cdept_id
WHERE gl_accvouch.ccode LIKE '5501%'
AND gl_accvouch.cdept_id LIKE '02%') as t
where iyperiod LIKE '201411'
ORDER BY code.ccode_name