分组由一个列与完全外部联接oracle

时间:2016-10-24 02:13:48

标签: sql oracle group-by outer-join

我有以下查询...

SELECT msn.id_notificacion AS notifiId, plt.planta_id AS plantaId, plt.planta_desc AS plantaDesc, orgPlt.org_id AS orgIdPlanta, 
orgPlt.org_desc AS orgDescPlanta, age.agencia_id AS agenciaId, age.agencia_desc AS agenciaDesc, orgAge.org_id AS orgIdAgencia, 
orgAge.org_desc AS orgDescAgencia, msn.user_contac AS usuario, msn.email_orig AS correo 
FROM cat_cpd_orig_ip msn 
FULL OUTER JOIN cat_plantas_erp plt ON msn.planta_id = plt.planta_id 
FULL OUTER JOIN cat_planta_loc pltLoc ON plt.planta_id = pltLoc.planta_id 
FULL OUTER JOIN cat_organizacion_adi orgPlt ON pltLoc.org_id = orgPlt.org_id 
FULL OUTER JOIN cat_agencia_erp age ON msn.agencia_id = age.agencia_id 
FULL OUTER JOIN cat_agencia_loc ageLoc ON age.agencia_id = ageLoc.agencia_id 
FULL OUTER JOIN cat_organizacion_adi orgAge ON ageLoc.org_id = orgAge.org_id 
WHERE msn.id_notificacion IS NOT NULL GROUP BY usuario ORDER BY usuario

但是当我对结果进行分组时,我有以下错误......

ORA-00904: "USUARIO": identificador no valido
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error en la línea: 11, columna: 48

我的查询返回以下结果......

27  4570    BLM_ATITALAQUIA                     63  BARCEL                  PRUEBA PLANTA TRES  prueba.planta_3@grupobimbo.com
9   109     WM_MEXICO                           62  BIMBO                   PRUEBA PLANTA DOS   prueba.planta_2@grupobimbo.com
8   727     STE_MARINELA VILLAHERMOSA           62  BIMBO                   PRUEBA PLANTA DOS   prueba.planta_2@grupobimbo.com
29  1225    BLM_LAGUNA                          63  BARCEL                  PRUEBA PLANTA TRES  prueba.planta_3@grupobimbo.com
28  1605    BLM_CDIS OCCIDENTE                  63  BARCEL                  PRUEBA PLANTA TRES  prueba.planta_3@grupobimbo.com
3   5483    GLO_MEXICO                          64  EL GLOBO                PRUEBA PLANTA UNO   prueba.planta_1@grupobimbo.com

但我需要以下结果......

3   5483    GLO_MEXICO                          64  EL GLOBO                PRUEBA PLANTA UNO   prueba.planta_1@grupobimbo.com
9   109     WM_MEXICO                           62  BIMBO                   PRUEBA PLANTA DOS   prueba.planta_2@grupobimbo.com
27  4570    BLM_ATITALAQUIA                     63  BARCEL                  PRUEBA PLANTA TRES  prueba.planta_3@grupobimbo.com

我需要通过' usuario'对结果进行分组,你能帮帮我吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

您不能在GROUP BY msn.user_contac ORDER BY msn.user_contac for Oracle中使用表别名。因此,对您的错误的明显修复是:

SELECT

但是,这只会产生另一个错误 - GROUP BY中有很多列没有聚合,而不是GROUP BY。它们会导致另一个错误。

您的问题没有说明您想要做什么。它只提到 #define PROC_BASIC_INFO 0 #define NT_WOW64_QUERY_INFORMATION_PROCESS_64_NAME "NtWow64QueryInformationProcess64" #define NT_WOW64_READ_VIRTUAL_MEMORY_64_NAME "NtWow64ReadVirtualMemory64" typedef UINT64 SYM; typedef SIZE_T SIZE_T64; HWND WINDOW_HANDLE; HANDLE PROC_HANDLE; DWORD PROC_ID; UINT address; UINT64 address64; SIZE_T bytesRead; SIZE_T64 bytesRead64; using namespace std; //initialize variables for importing of essential 64 bit reading functions //from ntdll typedef NTSTATUS(NTAPI *FUNC_NtReadVirtualMemory64) ( IN HANDLE ProcessHandle, IN PVOID64 BaseAddress, OUT PVOID Buffer, IN ULONGLONG BufferLength, OUT PULONGLONG ReturnLength OPTIONAL ); typedef NTSTATUS (NTAPI *FUNC_NtWow64QueryInformationProcess64) ( IN HANDLE ProcessHandle, IN ULONG ProcessInformationClass, OUT PVOID ProcessInformation64, IN ULONG Length, OUT PULONG ReturnLength OPTIONAL ); struct PROCESS_BASIC_INFORMATION64 { SYM Reserved1; SYM PebBaseAddress; SYM Reserved2[2]; SYM UniqueProcessId; SYM Reserved3; /* NTSTATUS ExitStatus; ULONG64 PebBaseAddress; ULONG64 AffinityMask; LONG BasePriority; UINT64 Reserved1; ULONG64 UniqueProcessId; ULONG64 InheritedFromUniqueProcessId; */ }; HINSTANCE ntdll = LoadLibrary("ntdll.dll"); FUNC_NtWow64QueryInformationProcess64 NtWow64QueryInformationProcess64 = (FUNC_NtWow64QueryInformationProcess64)GetProcAddress(ntdll, NT_WOW64_QUERY_INFORMATION_PROCESS_64_NAME); FUNC_NtReadVirtualMemory64 NtReadVirtualMemory64 = (FUNC_NtReadVirtualMemory64)GetProcAddress(ntdll, NT_WOW64_READ_VIRTUAL_MEMORY_64_NAME); int Init32To64MemoryRead(const char* windowClass, const char* caption, SYM addressOffset) { DWORD cbNeeded; DWORD dwdResult; HMODULE mainModule; BOOL enumResult; ULONG read_length=0; HINSTANCE ntdll; PROCESS_BASIC_INFORMATION64 procInfo; ZeroMemory(&procInfo, sizeof(procInfo)); //Get the window handle WINDOW_HANDLE = FindWindow(windowClass, NULL); if (WINDOW_HANDLE == NULL) { //Window was not foud return 10; } //Get the process ID dwdResult = GetWindowThreadProcessId(WINDOW_HANDLE, &PROC_ID); if (dwdResult == 0) { //Getting Process ID failed return 20; } //Open the process PROC_HANDLE = OpenProcess(PROCESS_ALL_ACCESS, false, PROC_ID); if (PROC_HANDLE == NULL) { //Process failed to open return 30; } DWORD result; //Query Proc Information to get .exe entry point result = NtWow64QueryInformationProcess64( PROC_HANDLE, 0, &procInfo, sizeof(procInfo), &read_length); if (result != 0) { cerr << "Query Information Process has failed" << endl; return 40; } address64 = (procInfo.PebBaseAddress + addressOffset); cerr << address64 << endl; string number; stringstream stristream; stristream << address64; stristream >> number; byte testByte = 0; (byte)ReadMemory64<byte>(testByte); system("PAUSE"); return 1; } template <typename _ret_t> _ret_t ReadMemory64(_ret_t& ret) { NTSTATUS result = NtReadVirtualMemory64(PROC_HANDLE, (void*)address64, &ret, 8, NULL); ///* Debug # when too lazy for breakpoints cerr <<"value: " << ret << endl; cerr << "Error Code: " << GetLastError() << endl; if (result != 0) { cerr << "ReadMemory Failed.\r\nAddress: " << address64 << "\r\nSize: " << sizeof(_ret_t) << "\r\nResult: " << result << endl; cerr << "NtReadVirtualMemory64 has failed" << endl; system("PAUSE"); } //*/ return ret; }; 错误。所以,这回答了你的问题,但它并没有解决你的问题。

您可能想要提出另一个问题,并对您尝试做的事情做出更多解释,可能包含样本数据和预期结果。