使用JOIN从两个表中选择数据后,我得到NULL

时间:2019-05-31 05:47:06

标签: oracle plsql

我正在尝试合并一个表中的数据和另一个表中的数据以获取员工列表。

情况正在发生。在一个表(t1-> KPOL)中,我有

这样的列
SIFRA_RAD, DAT_IZD, POLICA, MAT_BROJ, MJE_SIG, UL_BROJ, OPSTINA, DAT_IZD

还有另一个表(t2-> SIFRAD)我有列

SIFRA_R, IME, OSTALI_POD, DATUM_UNOSA, DATUM_PROMJENE, RADNIk_UNIO, DATUM_ISTEKA

这是我的数据的表格结构。

KPOL

  -------------------------------------------------Table KPOL------------------------------------------------------------------------------------------------
    SIFRA_RAD    DAT_IZD    POLICA      MAT_BROJ              MJE_SIG       UL_BROJ             OPSTINA              DAT_IZD

1.  "7654"      "1.1.2009"  "Z1A2B"      "06051987215444"       "USA"        "Neka Tamo 21"     "Jerricho"           "1.1.2015"
2   "4581"      "1.2.2007"  "A58547"     "65412398766666"       "DEU"        "Love Sthrase"     "Munich"             "1.2.2012"
3.  "00547"     "1.3.2013"  "65A565"     "44654789621789"       "GR"         "Huston Street"        "London"         "1.3.2012"
4.  "00214"     "1.3.2013"  "789789"     "28736428742313"       "USA"        "Next Street"      "Munchester"         "1.4.2013" 
5.  "00547"     "1.4.2013"  "789856"     "74789798564656"       "USA"        "Pro Nano 21"      "Munchester"         "1.5.2013" 
6.  "00654"     "4.4.2013"  "657989"     "78965423413213"       "USA"        "iuadsgdkj"        "Hamburg"             "6.3.2013"

-----------------------------------------------------------------------------------------------------------------------------------------------------------

SIFRAD

    -----------------------------------------Table SIFRAD-------------------------------------------------------------------------------------------------------    
 SIFRA_R        IME     OSTALI_POD      DATUM_UNOSA   DATUM_PROMJENE    RADNIK_UNIO DATUM_ISTEKA
    00214       Test123     Head of IT      31.12.2012  1.1.2013    333333123   1.5.2019
    00547       Aladin      Economic        8.5.2012    2.3.2013    32111111    31.12.2012
    00654       TestTest    Head of Management  2.2.2013    4.5.2014    11111111    1.1.2016
    0214        AaBbCc      Business        3.2.2014    6.5.2014    66666666    2.9.2019
    --------------------------------------------------------------------------------------------------------------------------------------------------------------

合并SIFRA_RAD(表KPOL),IME(表SIFRAD),DAT_IZD(表KPOL)后,它看起来应该像这个

SIFRA_RAD     IME        DAT_IZD
------------------------------------
"00654"     "TestTest   "1.4.2013"
"00547"     "Aladin "   "1.5.2013"
"00214"     "AaBbCc"    "4.4.2013"

它应在(DAT_IZD)

中显示所有员工如何发布2013 year政策

到目前为止,我所做的是以下查询:

SELECT P.SIFRA_RAD, S.IME, P.DAT_IZD
FROM AUTO.SIFRAD S
LEFT JOIN AUTO.KPOL P ON S.IME = P.SIFRA_RAD 
                      AND EXTRACT(YEAR FROM P.DAT_IZD) = 2013;

但是到目前为止,我无法在表中获取任何数据。

在我使用SELECTKPOL的语句通过使用以下查询选择SIFRA_RADDAT_IZD之后,我得到:

select sifra_rad, dat_izd 
from kpol 
where extract(year from dat_izd) = '2013'  
order by dat_izd asc

我相信问题来自我的查询。谁能帮助我在这里找到问题所在?

KPOL

SIFRA_RAD   DAT_IZD
----------------------    
00654       1.1.2007
00654       1.1.2007
00221       1.1.2007
00698       2.1.2007
00987       3.3.2013
00214       3.4.2013
00698       3.5.2013
etc     etc

1 个答案:

答案 0 :(得分:1)

您是否应该在import React, { useState, useEffect, useRef, useReducer } from "react"; import ReactDOM from "react-dom"; const items1 = []; for (let i = 0; i < 10; i++) { items1.push("top"); } const items2 = []; for (let i = 0; i < 10; i++) { items2.push("bottom"); } const App = () => { const [hasScrolled, setHasScrolled] = useState(false); const [tops, addTopItem] = useReducer(state => { const stateCopy = [...state]; stateCopy.push(Math.random()); return stateCopy; }, items1); const [bottoms, addBottomItem] = useReducer(state => { const stateCopy = [...state]; stateCopy.unshift(Math.random()); return stateCopy; }, items2); const middle = useRef(null); const container = useRef(null); const center = () => { if (hasScrolled) return; container.current.scrollTo( 0, middle.current.offsetTop - container.current.offsetTop - container.current.clientHeight / 2 ); }; const updater = () => { setInterval(() => { addTopItem(); if (container.current && middle.current) center(); }, 500); setInterval(() => { addBottomItem(); if (container.current && middle.current) center(); }, 700); }; const userScrollHandler = e => { console.log("user scrolled"); setHasScrolled(true); }; useEffect(() => { center(); updater(); }, []); return ( <div ref={container} onWheel={userScrollHandler} style={containerStyle}> {tops.map((item, idx) => { return ( <div key={idx} style={itemStyle}> {item} </div> ); })} <div ref={middle} style={middleItemStyle}> Middle </div> {bottoms.map((item, idx) => { return ( <div key={idx} style={itemStyle}> {item} </div> ); })} </div> ); }; const containerStyle = { margin: "0 auto", marginTop: "10vh", height: "400px", width: "300px", background: "#eee", overflow: "auto" }; const itemStyle = { width: "100%", height: "40px", borderBottom: "1px solid blue", display: "flex", justifyContent: "center", alignItems: "center" }; const middleItemStyle = { ...itemStyle }; middleItemStyle.background = "lime"; const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement); 上联接表,例如

SIFRA

您的查询连接了select p.sifra_rad, s.ime, p.dat_izd from kpol p join sifrad s on p.sifra_rad = s.sifra_r where extract (year from p.izd_dat) = 2013 IME,这似乎是不正确的。

[编辑,带有示例数据]

SIFRA