entity.entity_firstname as entityentityfirstname, sum(creditnoteitem.amount)as sumcreditnoteitem_amount FROM creditnote LEFT JOIN creditnoteitem on creditnote.creditnoteid = creditnoteitem.creditnoteid LEFT JOIN实体ON creditnote.customerid = entity.entityid LEFT JOIN salespersonnel_tbl ON entity_tbl.entityid = entitysalespersonnel .entityid LEFT JOIN人员ON entitysalespersonnel.personnelid = personnel.personnelid WHERE to_date(to_char(salestaxinvoice.processed,'yyyy-mm-dd') ,'yyyy-mm-dd')在'2013-01-01'和'2013-01-31'之间 personneluserid ='P10' AND(maentity_tbl。 entityuserid='A001' OR maentity_tbl。entityuserid='A002') GROUP BY entity.entityid, entity.entityuserid, entity.entity_firstname, creditnoteitem_tbl.amount ORDER BY entity.entityuserid ASC 结果: entityuserid,entityfirstname ,salestaxinvoiceitem_netamount,sumcreditnote_amount,结果 A001,Kesha,12,000,1,200,10,800 A002, Frank,9,000,4,000,5,000 A003,Paula,5,000,2,500,2,500 How do I get the result below,combining two queries?I want. Together with the results below.code 1:salestaxinvoiceSELECTentity.entityid as entity_entityid,entity.entityuserid as entity_entityuserid,entity.entity_firstname as entity_entity_firstname,personnel.personneluserid as personnel_personneluserid,personnel.personnelfirstname as personnel_personnelfirstname,sum(salestaxinvoiceitem.netamount) as sumnetamountFROMsalestaxinvoice LEFT JOIN salestaxinvoiceitem ON salestaxinvoice.salestaxinvoiceid = salestaxinvoiceitem.salestaxinvoiceidLEFT JOIN personnel ON arsalestaxinvoice.personnelid_sales = personnel_tbl.personnelidLEFT JOIN matunit on salestaxinvoiceitem.sourceid_matunitid = matunit.matunitidLEFT JOIN mat on matunit.matunituserid = mat_tbl.matuseridLEFT JOIN entity on salestaxinvoice.customerid = entity_tbl.entityidLEFT JOIN matcategory ON mmmatunit.matcategoryid = matcategory.matcategoryid WHERE to_date(to_char(salestaxinvoice.processed ,'yyyy-mm-dd'),'yyyy-mm-dd') between '2013-01-01' and '2013-01-31'AND personneluserid = 'P10'AND(matcategory.matcategoryid <> '010000')AND (maentity_tbl."entityuserid" = 'A001'OR maentity_tbl."entityuserid" = 'A002')GROUP BYentity.entityid,entity.entityuserid ,entity.entity_firstname ,personnel.personneluserid ,personnel.personnelfirstname ,salestaxinvoiceitem.netamount code 2:creditnoteSELECT distinctentity.entityid as entityid,entity.entityuserid as entityentityuserid,entity.entity_firstname as entityentityfirstname,sum(creditnoteitem.amount) as sumcreditnoteitem_amountFROM creditnote LEFT JOIN creditnoteitem ON creditnote.creditnoteid = creditnoteitem.creditnoteid LEFT JOIN entity ON creditnote.customerid = entity.entityid LEFT JOIN salespersonnel_tbl ON entity_tbl.entityid = entitysalespersonnel.entityid LEFT JOIN personnel ON entitysalespersonnel.personnelid = personnel.personnelidWHEREto_date(to_char(salestaxinvoice.processed ,'yyyy-mm-dd'),'yyyy-mm-dd') between '2013-01-01' and '2013-01-31'personneluserid = 'P10'AND (maentity_tbl."entityuserid" = 'A001' OR maentity_tbl."entityuserid" = 'A002')GROUP BYentity.entityid,entity.entityuserid,entity.entity_firstname,creditnoteitem_tbl.amountORDER BYentity.entityuserid ASCRESULT:entityuserid , entityfirstname , salestaxinvoiceitem_netamount , sumcreditnote_amount , result A001 , Kesha , 12,000 , 1,200 , 10,800 A002 , Frank , 9,000 , 4,000 , 5,000 A003 , Paula , 5,000 , 2,500 , 2,500推荐答案 UNION或者 string query =bla bla bla; string query2 =bla bla bla bla; query = query2 +UNION+bla bla bla; UNION or string query ="bla bla bla";string query2 ="bla bla bla bla";query = query2 + " UNION " +"bla bla bla"; 这篇关于如何结合两个查询获得以下结果?我想要。加上下面的结果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 21:51