Sunday 11 March 2018

चलती - औसत - ओरेकल - समारोह


यदि आप यह संदेश देखते हैं, तो आपका ब्राउज़र या तो अक्षम है या जावास्क्रिप्ट का समर्थन नहीं करता है इस सहायता प्रणाली की पूर्ण विशेषताओं का उपयोग करने के लिए, जैसे खोज करना, आपके ब्राउज़र में जावास्क्रिप्ट समर्थन सक्षम होना चाहिए। सामान्य मूविंग एवरेज के साथ वेटेड मूविंग एवरेज, जो कि कोट वॉंडलॉट में प्रत्येक डेटा वैल्यू जिसमें गणना की जाती है, को एक समान महत्व या वजन दिया जाता है। यह आमतौर पर मामला है, विशेष रूप से वित्तीय मूल्य डेटा विश्लेषण में, अधिक कालानुक्रमिक रूप से हाल के डेटा में अधिक वजन लेना चाहिए। इन मामलों में, भारित मूविंग औसत (या घातीय मूविंग औसत - निम्न विषय देखें) कार्यक्षमता अक्सर पसंदीदा है बारह महीनों के लिए बिक्री आंकड़ों के मूल्यों की एक ही तालिका पर विचार करें: भारित मूविंग औसत की गणना करने के लिए: मूविंग औसत गणना (यानी गणना उद्धरण चिह्न के आकार) में कितने अंतराल आंकड़े शामिल हैं। अगर गणना विंडो को एन कहा जाता है, तो खिड़की में सबसे हालिया डेटा वैल्यू को एन से गुणा किया जाता है, अगले सबसे हाल ही में एन -1 के साथ गुणा किया जाता है, मान से पहले एन -2 से गुणा किया जाता है और सभी मानों के लिए खिड़की में। उस विंडो पर वेटेड मूविंग एक्शन देने के लिए वजन के योग से गुणा किए गए सभी गुणों का योग विभक्त करें। ऊपर वर्णित अनुगामी औसत स्थिति के अनुसार एक नए कॉलम में वेटेड मूविंग औसत मूल्य को रखें। इन चरणों को स्पष्ट करने के लिए, विचार करें कि दिसंबर में बिक्री के 3 महीने के वेटेड मूविंग एवरेज की आवश्यकता है (बिक्री मूल्यों की उपरोक्त तालिका का उपयोग करके) उद्धरण 3-महीने का मतलब है कि गणना उद्धरण बिंदु 3 है, इसलिए इस मामले के लिए वेटेड मूविंग औसत गणना एल्गोरिथ्म होना चाहिए: या, अगर 3 माह का वेटेड मूविंग औसत का आंकलन संपूर्ण मूल रेंज के आधार पर किया गया, तो परिणाम होंगे : 3 महीने भारित मूविंग औसत पूर्व में हम चर्चा करते हैं कि पोस्टग्रेज़ में रोलिंग औसत कैसे लिखें। लोकप्रिय मांग से आप यह दिखा रहे थे कि MySQL और SQL सर्वर में ऐसा कैसे करना है। अच्छी तरह से इस तरह से शोर चार्ट की व्याख्या कैसे करें: इस तरह से 7-दिवसीय पूर्ववर्ती औसत रेखा के साथ: बिग आइडिया ऊपर दिए गए हमारा पहला ग्राफ़ बहुत ही शोर और कड़ी मेहनत से उपयोगी जानकारी प्राप्त करना है। हम अंतर्निहित डेटा के ऊपर 7-दिवसीय औसत की साजिश रचने से इसे चिकना कर सकते हैं। यह विंडो फ़ंक्शंस, स्वयं मिलकर, या सहसंबद्ध subqueries के साथ किया जा सकता है - अच्छी तरह से पहले दो कवर। अच्छी तरह से शुरुआती औसत से शुरू होता है, जिसका अर्थ है कि महीने के 7 वें दिन का औसत अंक पहले सात दिनों का औसत है। जाहिरा तौर पर यह दाईं तरफ ग्राफ में स्पाइक्स को बदलता है, क्योंकि एक बड़े स्पाइक का औसत निम्न सात दिनों में होता है। सबसे पहले, एक इंटरमीडिएट गणना तालिका बनाएँ हम प्रत्येक दिन के लिए कुल साइनअप पर औसत गणना करना चाहते हैं। यह मानते हुए कि हमारे पास एक नया उपयोगकर्ता प्रति पंक्ति और एक टाइमस्टैम्प बनियाट के साथ एक विशिष्ट उपयोगकर्ता तालिका है, हम अपनी कुल पंजीकरण तालिका बना सकते हैं जैसे: Postgres और SQL सर्वर में आप इसका उपयोग सीटीई के रूप में कर सकते हैं MySQL में आप इसे अस्थायी तालिका के रूप में सहेज सकते हैं। पोस्टग्रेस रोलिंग औसत सौभाग्य से पोस्टग्रेज़ में खिड़की का कार्य होता है जो चल रहे औसत की गणना करने का सबसे आसान तरीका है। यह क्वेरी मानता है कि तिथियों में अंतर नहीं होता है पिछले 7 तारीखों से नहीं, पिछले सात पंक्तियों से क्वेरी औसत है यदि आपके डेटा में अंतराल है, तो उसे जनरेटरीज के साथ भरें या घने दिनांक पंक्तियों के साथ तालिका के साथ जुड़ें। MySQL रोलिंग औसत MySQL विंडो फ़ंक्शन का अभाव है, लेकिन हम आत्म-जुड़ने का उपयोग करते हुए एक समान गणना कर सकते हैं। हमारी गिनती तालिका में प्रत्येक पंक्ति के लिए, हम प्रत्येक पंक्ति में शामिल होते हैं जो पिछले सात दिनों के भीतर थी और औसत लेते थे। यह क्वेरी स्वतः तिथि के अंतराल को व्यवस्थित करती है, क्योंकि हम पूर्ववर्ती एन पंक्तियों की बजाय किसी तारीख सीमा के भीतर पंक्तियों को देख रहे हैं। एसक्यूएल सर्वर रोलिंग औसत एसक्यूएल सर्वर में खिड़की का कार्य होता है, इसलिए रोलिंग औसत की गणना या तो पोस्टग्रेस शैली या माइस् SQL शैली में की जा सकती है। सादगी के लिए, स्वयं शामिल होने के साथ MySQL संस्करण का उपयोग कर रहे थे। यह संकल्पनात्मक रूप से MySQL के समान है केवल अनुवाद की तारीख का कार्य और कॉलम द्वारा स्पष्ट रूप से नामित समूह है। अन्य औसत हम इस पोस्ट के 7-दिवसीय अनुगामी औसत पर ध्यान केंद्रित करते हैं। यदि हम 7-दिवसीय अग्रणी औसत को देखना चाहते हैं, तो यह अन्य दिशाओं में दिनांक को छांटने के लिए उतना सरल है। यदि हम एक केन्द्रित औसत, पोस्टेड का उपयोग करना चाहते हैं: MySQL के बाद 3 पूर्ववर्ती और 3 के बीच की पंक्तियां: signups. date-3 के बीच और MySQL SQL सर्वर में signups. date 3: dateadd के बीच (दिन, -3, साइनअप तारीख) और dateadd (दिन, 3, signups. date) मैं आसानी से MA200 गणना करने में सक्षम हूँ। मेरी वर्तमान क्वेरी उस तरह के आधार जैसा दिखती है (ROWNUMBER () को चुनें (STOCKCODE ORDER BY pxDate द्वारा) rowno। A। मूल्य से), बेस 2 के रूप में (MA200160160160160160 का चयन करें) जब राउनो जीटी 200 तब औसत (करीब) ओवर ( एसओएसीएआर द्वारा विभाजन के बाद से पीएक्सडीएटी आरओईएस द्वारा 200 प्रीसीडिंग और मौजूदा रोव्स) एमए 200, एमए 100160160160160160 के रूप में अन्य रिक्त समापन, जब राउनो जीटी 100 तब औसत (करीब) ओवर (स्टॉककोड द्वारा विभाजित करके ऑर्डर करके pxDate ROWS के साथ 100 प्रसंस्करण और वर्तमान पंक्ति) अन्य निरर्थक अंत MA100, MA50160160160160160 के मामले में जब rowno gt 50 तब औसत (बंद) पर (STOCKCODE द्वारा विभाजन द्वारा pxDate ROWS BY pxDate ROWS 50 PRECEDING और वर्तमान ROW) अन्य के रूप में समाप्त MA50, ख। बेस से) बेस 2 से चुनें। : 6 ऑरेकल में घातीय चलती औसत की गणना करने के लिए कोई फ़ंक्शन यह नही है कि मैं जानता हूँ। यदि एक 5 अवधि ईएमए की गणना कुछ नीचे की तरह है, तो एएमए 200 की गणना करने के लिए कोड वापस करने वाली एक स्क्रिप्ट को लिखना काफी आसान होगा: एटबिन द्वारा 30.5.2010 18:29 यदि हाल के मूल्यों में अधिक वजन होना चाहिए, तो शक्ति ( (1 -: कारक), एन) को दूसरी तरफ लागू करना चाहिए क्षमा करें, मुझे समझ में नहीं आता कि आपका प्रश्न क्या है जब भी आपको कोई समस्या आती है, तो थोड़ा सा नमूना डेटा (बनाएं तालिका और INSERT स्टेटमेंट्स) और उस डेटा से प्राप्त परिणाम देखें। हमेशा बताइए कि ओरेकल का कौन सा संस्करण आप उपयोग कर रहे हैं जितना संभव हो उतना सरल बनाएं उदाहरण के लिए, 200 से अधिक पंक्तियों की औसत के बजाय, ऐसी समस्या पोस्ट करें जहां आप शायद औसत 3 पंक्तियों से अधिक हो। तिथि करीब stockname एसएमए (सरल चलती औसत की गणना करने के औसत, विभाजन क्वेरी और विंडोइंग उपयोग करने में सक्षम) 03-मई-101601601601601603.69160160160160160CAPITALAND लिमिटेड अशक्त 04-मई-101601601601601603.66160160160160160CAPITALAND लिमिटेड अशक्त 05-मई-101601601601601603.63160160160160160CAPITALAND लिमिटेड अशक्त 06-मई-101601601601601603.6160160160160160CAPITALAND लिमिटेड अशक्त 07-मई-101601601601601603.63160160160160160CAPITALAND लिमिटेड 3.642 10-मई-101601601601601603.7160160160160160CAPITALAND लिमिटेड 3.644 03-मई-101601601601601601.68160160160160160YANLORD भूमि ग्रुप लिमिटेड अशक्त 04-मई-101601601601601601.64160160160160160YANLORD भूमि ग्रुप लिमिटेड अशक्त 05-मई-101601601601601601.61160160160160160YANLORD भूमि ग्रुप लिमिटेड अशक्त 06- मई-101601601601601601.6160160160160160YANLORD लैंड ग्रुप लिमिटेड नल 07-मई-101601601601601601.61160160160160160YANLORD भूमि ग्रुप लिमिटेड 1.628 10-मई-101601601601601601.6716016016016016067160160160160160YANLORD भूमि ग्रुप लिमिटेड 1.626 के लिए 2 स्टॉक कैपिटलंड और ynlord को देखते हुए 3 से 10 मई के बीच की अवधि। मैं सामान्य औसत 5 दिनों की औसत गणना औसत फ़ंक्शन का उपयोग कर सकते हैं। समस्या यह है कि मुझे 5 दिनों की घातीय चलती औसत ढूँढने में परेशानी हो रही है ध्यान दें: मेरा डेटा बेस वर्तमान में कुछ वर्षों के लिए स्टॉक डेटा पर 1000 से अधिक है और मुझे गणना की जाने वाली घातीय चलती औसत की अलग अवधि है, इसलिए मैं क्यों पूछ रहा हूं कि क्या कोई फ़ंक्शन उपलब्ध है जो मुझे पता नहीं है। घातीय चलती औसत की गणना के लिए कोई मानक कार्य उपलब्ध नहीं है। लेकिन यह ऐसी गणना का प्रकार है जहां मॉडल खंड वास्तव में चमकता है: मैंने यहाँ वर्णित सूत्र के रूप में उपयोग किया है: download. oracledocscdE1203201docepm.921html internationaludioframeset. htmdocscdE1203201docepm.921htmlirstudioirstudio-15-74.html 1 quot (0) (0) वाह वह शांत है। मुझे नहीं पता था कि ऐसी बात कॉलल्ड मॉडल थी। मैं इसके बारे में और अधिक शोध करूँगा और देखें कि क्या मैं इसे लागू कर सकता हूं। बहुत सारे लोग SQL के विश्लेषण और रिपोर्टिंग उपचार के लिए एसक्यूएल के रूप में विंडो फ़ंक्शंस में इनपुट के रूप में कार्य करता है शून्य सिमेंटिक एसक्यूएल कुल कार्यों के लिए शून्य शब्दार्थों से मेल खाते हैं। अन्य शब्दों को उपयोगकर्ता द्वारा परिभाषित कार्यों से, या विंडो फ़ंक्शन के भीतर DECODE या CASE अभिव्यक्ति का उपयोग करके प्राप्त किया जा सकता है। तार्किक ऑफसेट के साथ विंडिंग फ़ंक्शंस एक तार्किक ऑफसेट को स्थिरांक के साथ निर्दिष्ट किया जा सकता है जैसे कि RANGE 10 PRECEDING या एक अभिव्यक्ति जो एक निरंतर, या अंतराल विनिर्देश द्वारा आरएएनजीई आरएएनजीई एमएडएएमईआरईआर प्रीसिंग या एक अंतराल के लिए मूल्यांकन की अभिव्यक्ति जैसे एक अंतराल विनिर्देश द्वारा मूल्यांकन करता है। तार्किक ऑफसेट के साथ, फ़ंक्शन में ORDER BY अभिव्यक्ति सूची में केवल एक अभिव्यक्ति हो सकती है, NUMERIC के लिए संगत प्रकार के साथ अगर ऑफसेट संख्यात्मक होता है, या यदि कोई अंतराल निर्दिष्ट किया जाता है तो DATE। उदाहरण 21-7 संचयी एकत्रीकरण कार्य निम्न उदाहरण 1999 में तिमाही द्वारा ग्राहक आईडी द्वारा एकत्रित राशि का एक उदाहरण है: इस उदाहरण में, विश्लेषणात्मक कार्य SUM परिभाषित करता है, प्रत्येक पंक्ति के लिए, एक विण्डो जो विभाजन की शुरुआत में शुरू होता है (अनबॉल्ड प्रीसीडिंग ) और समाप्त होता है, डिफ़ॉल्ट रूप से, वर्तमान पंक्ति में। इस उदाहरण में नेस्टेड एसयूएम की ज़रूरत है क्योंकि हम एक एसएएम को एक ऐसे मूल्य पर प्रदर्शन कर रहे हैं जो खुद एसएम है। विश्लेषणात्मक कुल कार्यों में नेस्टेड एग्रीगेशन्स बहुत अक्सर उपयोग किया जाता है उदाहरण 21-8 कुल कार्य चलाना एक ग्राहक के लिए, वर्तमान माह के लिए चलती हुई औसत बिक्री और पिछले दो महीनों के लिए समय-आधारित विंडो शो का यह उदाहरण: नोट करें कि तीन महीनों के लिए पहली दो पंक्तियों में औसत गणना चलती है आउटपुट डेटा निर्दिष्ट की तुलना में एक छोटे अंतराल आकार पर आधारित होता है क्योंकि विंडो गणना क्वेरी द्वारा प्राप्त डेटा से पहले तक नहीं पहुंच सकती। आपको परिणाम सेट की सीमाओं पर पाए जाने वाले विभिन्न विंडो आकारों पर विचार करना होगा। दूसरे शब्दों में, आपको वही शामिल करने के लिए क्वेरी को संशोधित करने की आवश्यकता हो सकती है जो आप चाहते हैं। केंद्रित कुल फ़ंक्शन वर्तमान पंक्ति के केंद्र में केंद्रित विंडोिंग समेकित कार्यों की गणना सरल है। यह उदाहरण सभी ग्राहकों के लिए दिसंबर 1 999 के आखिर में एक हफ्ते के लिए एक केंद्रित चलती हुई औसत बिक्री की गणना करता है। वर्तमान पंक्ति के साथ एक दिन के लिए एक दिन की कुल औसत बिक्री और एक दिन मौजूदा पंक्ति के साथ-साथ मौजूदा पंक्ति के एक दिन बाद भी पता चलता है। उदाहरण 21-9 मध्यवर्ती कुल उत्पाद आउटपुट डेटा में चलने वाली औसत गणना केंद्रित प्रत्येक उत्पाद के लिए शुरुआती और समाप्ति पंक्तियां केवल दो दिनों पर आधारित हैं, क्योंकि विंडो गणना क्वेरी द्वारा प्राप्त डेटा से पहले तक नहीं पहुंच सकती। उपयोगकर्ताओं को परिणाम सेट की सीमाओं पर पाए जाने वाले अलग-अलग विंडो आकारों पर विचार करना होगा: क्वेरी को समायोजित करने की आवश्यकता हो सकती है। डुप्लिकेट्स की उपस्थिति में कुल मिलाकर कार्य चलाना निम्न उदाहरण दिखाता है कि कैसे विंडो समस्त फ़ंक्शन गणना मूल्यों जब डुप्लिकेट होते हैं, वह यह है, जब एकल क्रम मान के लिए कई पंक्तियों को वापस किया जाता है। क्वेरी निर्दिष्ट समय सीमा के दौरान कई ग्राहकों को बेची गई मात्रा को प्राप्त करता है। (हालांकि हम अपने बेस डेटा सेट को परिभाषित करने के लिए इनलाइन दृश्य का उपयोग करते हैं, इसका कोई विशेष महत्व नहीं है और इसे अनदेखा किया जा सकता है।) क्वेरी एक चलती विंडो को परिभाषित करती है जो मौजूदा पंक्ति की तारीख से 10 दिन पहले चलती है। नोट करें कि रेंगा कीवर्ड इस उदाहरण के विंडोिंग खंड को परिभाषित करने के लिए उपयोग किया जाता है। इसका मतलब यह है कि खिड़की रेंज में प्रत्येक मान के लिए कई पंक्तियां संभावित रूप से पकड़ सकती हैं। इस स्थिति में, डुप्लिकेट तारीख मान वाले पंक्तियों के तीन जोड़े हैं। उदाहरण 21-10 लॉजिकल ऑफसेट्स के साथ कुल कार्य को विन्डोइंग करना इस उदाहरण के आउटपुट में, 6 मई और 12 मई को छोड़कर सभी दिनांक डुप्लिकेट तिथियों के साथ दो पंक्तियां लौटाते हैं। मूल्यों की गणना कैसे की जाती है यह देखने के लिए आउटपुट के दाईं ओर टिप्पणी की गई संख्याओं की जांच करें। ध्यान दें कि प्रत्येक समूह कोष्ठक में एक दिन के लिए लौटाए गए मानों का प्रतिनिधित्व करता है। ध्यान दें कि यह उदाहरण तब लागू होता है जब आप ROWS कीवर्ड की बजाय RANGE कीवर्ड का उपयोग करते हैं। याद रखना भी महत्वपूर्ण है कि RANGE के साथ। आप केवल एडीआरईआर द्वारा एनालिटिक फ़ंक्शन ORDER BY क्लॉज में विश्लेषणात्मक कार्यों में उपयोग कर सकते हैं। ROWS कीवर्ड के साथ, आप विश्लेषणात्मक फ़ंक्शंस ORDER BY खंड में अभिव्यक्तियों द्वारा कई ऑर्डर का उपयोग कर सकते हैं। प्रत्येक पंक्ति के लिए विंडो आकार बदलते हैं एक ऐसी स्थिति है जहां एक निर्दिष्ट स्थिति के आधार पर प्रत्येक पंक्ति के लिए विंडो के आकार में भिन्नता है। उदाहरण के लिए, आप खिड़की को निश्चित तिथियों के लिए और दूसरों के लिए छोटा बना सकते हैं। मान लें कि आप तीन कार्यदिवसों के चलते औसत मूल्य की गणना करना चाहते हैं यदि आपके पास प्रत्येक कार्य दिवस के लिए प्रत्येक दिन के बराबर पंक्तियाँ हैं और कोई गैर-कार्य दिवस संग्रहीत नहीं किया गया है, तो आप एक भौतिक विंडो फ़ंक्शन का उपयोग कर सकते हैं। हालांकि, यदि ध्यान दिया गया शर्तों को पूरा नहीं किया गया है, तो आप खिड़की के आकार के पैरामीटर में अभिव्यक्ति का उपयोग करके अब भी चलती औसत की गणना कर सकते हैं। खिड़की आकार की विशिष्टता में अभिव्यक्ति कई अलग-अलग स्रोतों में की जा सकती है। अभिव्यक्ति एक तालिका में एक स्तंभ के संदर्भ हो सकती है, जैसे कि समय सारणी यह एक ऐसा कार्य भी हो सकता है जो वर्तमान पंक्ति में मानों के आधार पर विंडो के लिए उचित सीमा देता है। एक काल्पनिक शेयर मूल्य डेटाबेस के लिए निम्नलिखित कथन विंडो आकार सेट करने के लिए अपने RANGE खंड में एक उपयोगकर्ता परिभाषित कार्य का उपयोग करता है: इस कथन में, ttimekey एक दिनांक फ़ील्ड है यहां, एफएन एक निम्न निर्देश के साथ एक PLSQL फ़ंक्शन हो सकता है: 4 यदि ttimekey सोमवार है, मंगलवार यदि पिछले दिनों में से कोई छुट्टियां है, तो वह गिनती को उचित रूप से समायोजित कर सकता है। ध्यान दें, जब विंडो को किसी दिनांक फ़ंक्शन में ORDER BY के साथ एक दिनांक कॉलम पर निर्दिष्ट करते हुए निर्दिष्ट किया जाता है, तो इसे दिन की संख्या के लिए परिवर्तित किया जाता है। आप अंतराल शाब्दिक कनवर्ज़न फंक्शन भी इस्तेमाल कर सकते थे, जैसे कि NUMTODSINTERVAL (fn (ttimekey), DAY) के बजाय सिर्फ एफ एन (ttimekey) के बजाय एक ही बात आप एक PLSQL फ़ंक्शन भी लिख सकते हैं जो एक इंटरवल डेटाटाइप मान देता है। भौतिक ऑफसेट के साथ कुल मिलाकर कार्य को पंक्तियों में व्यक्त की गई विंडो के लिए, क्रमबद्ध अभिव्यक्ति निर्णायक परिणाम उत्पन्न करने के लिए अद्वितीय होनी चाहिए। उदाहरण के लिए, निम्नलिखित प्रश्न निर्धारक नहीं है क्योंकि टाइमिड इस परिणाम सेट में अद्वितीय नहीं है। उदाहरण 21-11 भौतिक ऑफसेट्स के साथ कुल कार्यों को विन्डोइंग करना इस समस्या को संभालने का एक तरीका टाइमआईड और प्रोडिड दोनों पर नतीजे सेट और ऑर्डर के लिए प्रॉड कॉलम जोड़ना होगा। FIRSTVALUE और LASTVALUE फ़ंक्शंस FIRSTVALUE और LASTVALUE फ़ंक्शन आपको विंडो से पहली और अंतिम पंक्तियों का चयन करने की अनुमति देते हैं। इन पंक्तियों को विशेष रूप से महत्वपूर्ण हैं क्योंकि वे गणना में बेसलाइन के रूप में अक्सर उपयोग किए जाते हैं। उदाहरण के लिए, एक विभाजन वाले शेयर डेटा को दिन-दिन का आदेश दिया जाता है, तो आप पूछ सकते हैं कि प्रत्येक दिन की बिक्री अवधि की पहली बिक्री दिन (प्रथमवींव) या तुलना की जा सकती है, या आप जानना चाह सकते हैं, बिक्री क्रम बढ़ाने में पंक्तियों के एक सेट के लिए , इस क्षेत्र में सबसे बड़ी बिक्री (एलएटीटीवीआरए) की तुलना में इस क्षेत्र में प्रत्येक बिक्री का प्रतिशत आकार क्या था IGNORE NULLS विकल्प का उपयोग FIRSTVALUE के साथ किया जाता है। यह सेट में पहले गैर-नल मान वापस लौटाएगा, या यदि सभी मान नल हों तो यदि IGNORE NULLS का उपयोग LASTVALUE के साथ किया जाता है यह सेट में अंतिम गैर-नल मान वापस लौटाएगा, या यदि सभी मान नल हैं तो IGNORE NULLS विकल्प विशेष रूप से एक सूची तालिका को लोकप्रिय बनाने में उपयोगी है। कुल कार्यों की रिपोर्टिंग एक क्वेरी के बाद संसाधित किया गया है, परिणामी पंक्तियों की संख्या या किसी कॉलम में औसत मूल्य को आसानी से एक विभाजन के भीतर गिना जा सकता है और अन्य रिपोर्टिंग कार्यों के लिए उपलब्ध कराया जा सकता है। कुल कार्यों की रिपोर्टिंग एक विभाजन में प्रत्येक पंक्ति के लिए समान कुल मान वापस करती है। NULLs के संबंध में उनका व्यवहार एसक्यूएल कुल कार्यों के समान है सिंटैक्स है: इसके अतिरिक्त, निम्नलिखित शर्तें लागू होती हैं: एक तारांकन () को केवल COUNT () DISTINCT में ही अनुमति दी जाती है, यदि केवल समेकित फ़ंक्शंस यह अभिव्यक्ति 1 मान की अनुमति देते हैं और मूल्य अभिव्यक्ति 2 कॉलम संदर्भ या समुच्चय से युक्त कोई मान्य अभिव्यक्ति हो सकती है। खंड द्वारा खंड उन समूहों को परिभाषित करता है जिन पर विंडोिंग फ़ंक्शंस की गणना की जाएगी। यदि खंड द्वारा भाग अनुपस्थित है, तो फ़ंक्शन पूरे क्वेरी परिणाम सेट पर गणना की जाती है। रिपोर्टिंग फ़ंक्शन केवल SELECT खंड या ऑर्डर बाय क्लॉज में प्रदर्शित हो सकते हैं। रिपोर्टिंग कार्यों का प्रमुख लाभ एक एकल क्वेरी ब्लॉक में डेटा के एकाधिक पास करना और क्वेरी प्रदर्शन को गति देने की उनकी क्षमता है। पूछताछ जैसे कि सेलसेल्स की संख्या को शहर की 10 से अधिक बिक्री की बिक्री के साथ अलग क्वेरी ब्लॉक्स के बीच जुड़ने की आवश्यकता नहीं है। उदाहरण के लिए, इस प्रश्न पर विचार करें कि प्रत्येक उत्पाद श्रेणी के लिए उस क्षेत्र का पता लगाएं जिसमें इसकी अधिकतम बिक्री होती है। अधिकतम रिपोर्टिंग समेकित फ़ंक्शन का उपयोग करके समकक्ष एसक्यूएल प्रश्न होगा: रिपोर्टिंग समेकित कार्य MAX (एसएम (एमएंडोलॉल्ड)) के साथ आंतरिक क्वेरी: रिटर्न पूरी क्वेरी हैं: उदाहरण 21-12 समस्त उदाहरण रिपोर्टिंग समेकित रिपोर्ट ने नेस्टेड प्रश्नों के साथ संयोजित किया है आप जटिल प्रश्नों को कुशलता से उत्तर देने के लिए। उदाहरण के लिए, क्या होगा अगर आप अपने सबसे महत्वपूर्ण उत्पाद उप-श्रेणियों में सर्वश्रेष्ठ बिक्री वाले उत्पादों को जानना चाहते हैं निम्नलिखित एक क्वेरी है जो प्रत्येक उत्पाद उपश्रेणी के लिए 5 शीर्ष-बिक्री वाले उत्पादों को पाता है जो अपनी उत्पाद श्रेणी में से 20 से अधिक बिक्री में योगदान देता है: RATIOTOREPORT फ़ंक्शन RATIOTOREPORT फ़ंक्शन मानों के सेट के योग के मान का अनुपात गणना करता है। यदि अभिव्यक्ति मूल्य अभिव्यक्ति नल के लिए मूल्यांकन करता है RATIOTOREPORT भी नल के लिए मूल्यांकन लेकिन यह हर तरह के मूल्यों की गणना के लिए शून्य के रूप में माना जाता है। इसका वाक्यविन्यास है: इसमें, निम्नलिखित पर लागू होता है: एक्सपीआर स्तंभ संदर्भ या समुच्चय को शामिल करने वाला कोई मान्य अभिव्यक्ति हो सकता है। खंड द्वारा भागीदारी उन समूहों को परिभाषित करता है जिन पर RATIOTOREPORT फ़ंक्शन को गणना किया जाना है। यदि खंड द्वारा भाग अनुपस्थित है, तो फ़ंक्शन पूरे क्वेरी परिणाम सेट पर गणना की जाती है। प्रत्येक चैनल के लिए बिक्री के RATIOTOREPORT की गणना करने के लिए, आप निम्न सिंटैक्स का उपयोग कर सकते हैं: LAGLEAD फ़ंक्शंस पंक्तियों की रिश्तेदार स्थिति विश्वसनीय ढंग से ज्ञात हो सकते हैं जब लैग और लीड फ़ंक्शन मूल्यों की तुलना करने के लिए उपयोगी होते हैं वे पंक्तियों की संख्या को निर्दिष्ट करके काम करते हैं जो लक्ष्य पंक्ति को मौजूदा पंक्ति से अलग करती हैं क्योंकि फ़ंक्शन एक तालिका के एक से अधिक पंक्ति तक स्वयं को शामिल किए बिना एक ही समय में पहुंच प्रदान करता है, इसलिए वे प्रोसेसिंग गति को बढ़ा सकते हैं। लैग फ़ंक्शन वर्तमान स्थिति से पहले दिए गए ऑफ़सेट पर एक पंक्ति तक पहुंच प्रदान करता है, और लीड फ़ंक्शन वर्तमान स्थिति के बाद दिए गए ऑफ़सेट पर एक पंक्ति तक पहुंच प्रदान करता है। लैगलेड सिंटैक्स ये फ़ंक्शंस निम्न सिंटैक्स हैं: ऑफसेट एक वैकल्पिक पैरामीटर है और 1 के लिए चूक है। डिफ़ॉल्ट एक वैकल्पिक पैरामीटर है और यदि ऑफसेट तालिका या विभाजन की सीमा के बाहर आता है तो वह मान लौटाया जाता है स्पैर्स डेटा पर अवधि-से-अवधि तुलना क्वेरी करने के लिए लैग लीड फंक्शंस का उपयोग करने के तरीके के बारे में रिपोर्टिंग के लिए डेटा डांसिफिकेशन देखें। FIRSTLAST फ़ंक्शंस FIRSTLAST कुल फ़ंक्शंस आपको डेटा सेट को रैंक करने और इसकी शीर्ष-रेंज वाली या नीचे-रेंज की पंक्तियों के साथ काम करने की अनुमति देती है। ऊपरी या निचले स्तर पर पंक्तियों को खोजने के बाद, एक समस्त कार्य किसी वांछित स्तंभ पर लागू होता है। यही है, सबसे पहले आपको कॉलम ए के रैंक पर जाने देता है, लेकिन कॉलम बी की प्रथम-रैंक वाली या अंतिम-रेंज वाली पंक्तियों पर लागू कुल योग का परिणाम वापस लौटा देता है। यह मूल्यवान है क्योंकि यह स्वयं-मिलन या सबक्वायरी की आवश्यकता से बचा जाता है, इस प्रकार प्रदर्शन सुधारना। ये फ़ंक्शंस सिंटैक्स एक नियमित समेकित कार्य से शुरू होता है (न्यूनतम MAX SUM. Agg। V. VARIANCE. STDDEV) जो प्रति समूह एकल रिटर्न वैल्यू का उत्पादन करता है। उपयोग रैंकिंग को निर्दिष्ट करने के लिए, FIRST LAST फ़ंक्शंस KEEP शब्द के साथ शुरू होने वाली एक नई धारा जोड़ें। FIRSTLAST सिंटैक्स ये फ़ंक्शंस निम्न वाक्यविन्यास हैं: ध्यान दें कि ऑर्डर बाय क्लॉज कई एक्सप्रेशंस ले सकता है। सबसे पहले नियमित रूप से समुच्चय के रूप में आप नियमित समस्त कार्य के रूप में समुच्चय के प्रथम पिछला परिवार का उपयोग कर सकते हैं। उदाहरण 21-15 प्रथमतम उदाहरण 1 निम्नलिखित प्रश्न हमें न्यूनतम मूल्य और हमारे उत्पादों की सूची मूल्य की तुलना करने देता है। प्रत्येक उत्पाद उपश्रेणी के लिए पुरुषों के कपड़े श्रेणी के भीतर, यह निम्न देता है: न्यूनतम न्यूनतम मूल्य वाले उत्पाद की सूची मूल्य न्यूनतम न्यूनतम कीमत सूची मूल्य उच्चतम न्यूनतम कीमत के साथ उत्पाद उच्चतम न्यूनतम मूल्य प्रथमतम रिपोर्टिंग समुच्चय के रूप में आप इसका उपयोग भी कर सकते हैं कुल कार्यों का रिपोर्ट करने के लिए समुच्चय के सबसे पहले परिवार एक उदाहरण का आकलन है कि पूरे साल के महीनों में सबसे बड़ी और कम से कम सिर की गिनती में वृद्धि हुई थी। इन कार्यों के लिए सिंटैक्स किसी अन्य रिपोर्टिंग समेकन के लिए सिंटैक्स के समान है। उदाहरण के लिए उदाहरण 21-15 के लिए FIRSTLAST पर गौर करें। क्या होगा अगर हम अलग-अलग उत्पादों की सूची मूल्यों को खोजना चाहते हैं और उनकी उपश्रेणी में उन उत्पादों की सूची की कीमतों की तुलना करना चाहते हैं जो कि उच्चतम और निम्नतम न्यूनतम कीमतें थीं निम्न क्वेरी से हमें रिपोर्टिंग के रूप में FIRSTLAST का उपयोग करके प्रलेखन उपश्रेणी के लिए जानकारी मिलती है समुच्चय। उदाहरण 21-16 फर्स्टलास्ट उदाहरण 2 रिपोर्टिंग समुच्चय के रूप में प्रथम और अंतिम कार्यों का उपयोग करना यह गणना में परिणाम को शामिल करना आसान बनाता है जैसे वेतन उच्चतम वेतन का प्रतिशत CUMEDIST फ़ंक्शन का उपयोग करने के लिए व्युत्क्रम प्रतिशतता फ़ंक्शन, आप मूल्यों के एक संच का संचयी वितरण (प्रतिशतय) पा सकते हैं। हालांकि, व्युत्क्रम ऑपरेशन (यह पता लगाना कि किसी निश्चित प्रतिशत्य के लिए मूल्य क्या है) न तो करना आसान है और न ही कुशलतापूर्वक गणना की गई है। इस कठिनाई को दूर करने के लिए, PERCENTILECONT और PERCENTILEDISC कार्य शुरू किए गए थे। इन दोनों के रूप में खिड़की रिपोर्टिंग कार्यों के साथ-साथ सामान्य समेकित कार्य भी उपयोग किया जा सकता है। इन फ़ंक्शंस को क्रमबद्ध विनिर्देश और पैरामीटर की आवश्यकता है, जो 0 और 1 के बीच एक प्रतिशतय मान लेते हैं। क्रमबद्ध विनिर्देश को एक अभिव्यक्ति के साथ एक ORDER BY खंड का उपयोग करके नियंत्रित किया जाता है। सामान्य सामान्य कार्य के रूप में उपयोग किए जाने पर, प्रत्येक आदेशित सेट के लिए यह एक एकल मान देता है। PERCENTILECONT। जो प्रक्षेप द्वारा गणना की गई एक निरंतर कार्य है, और PERCENTILEDISC जो एक कदम कार्य है जो असतत मूल्यों को मानता है। अन्य समुच्चय की तरह, PERCENTILECONT और PERCENTILEDISC समूहीकृत क्वेरी में पंक्तियों के समूह पर काम करते हैं, लेकिन निम्न अंतर के साथ: उन्हें 0 और 1 (समावेशी) के बीच एक पैरामीटर की आवश्यकता होती है। इस श्रेणी से निर्दिष्ट एक पैरामीटर त्रुटि का परिणाम होगा। यह पैरामीटर एक अभिव्यक्ति के रूप में निर्दिष्ट किया जाना चाहिए, जो एक निरंतर में मूल्यांकन करता है। उन्हें क्रमबद्ध विनिर्देश की आवश्यकता होती है इस प्रकार की विनिर्देश एक अभिव्यक्ति के साथ एक आदेश बाय क्लॉज है एकाधिक अभिव्यक्तियों की अनुमति नहीं है सामान्य समग्र सिंटेक्स उलटा प्रतिशत का आधार आधार हम इस खंड के उदाहरणों में उपयोग किए गए डेटा की 17 पंक्तियों को वापस करने के लिए निम्न प्रश्न का उपयोग करते हैं: PERCENTILEDISC (x) की गणना प्रत्येक समूह में CUMEDIST मान को स्कैन करके तब तक की जाती है जब तक कि आपको पहले से बड़ा नहीं मिलता या एक्स के बराबर जहां x निर्दिष्ट प्रतिशत्य मूल्य है उदाहरण क्वेरी के लिए जहां PERCENTILEDISC (0.5), परिणाम 5000 है, जैसा कि निम्नलिखित उदाहरण दिखाता है: PERCENTILECONT का परिणाम उन्हें क्रम देने के बाद पंक्तियों के बीच रैखिक प्रक्षेप द्वारा गणना किया जाता है। PERCENTILECONT (x) की गणना करने के लिए हम पहले पंक्ति संख्या आरएन (1x (n-1)) की गणना करते हैं, जहां n समूह में पंक्तियों की संख्या है और x निर्दिष्ट प्रतिशत्य मूल्य है। कुल फ़ंक्शन का अंतिम परिणाम पंक्ति संख्या CRN CEIL (RN) और FRN FLOOR (RN) में पंक्तियों के मूल्यों के बीच रैखिक प्रक्षेप द्वारा गणना की जाती है। अंतिम परिणाम होगा: PERCENTILECONT (X) यदि (सीआरएन एफआरएन आर एन), फिर (आरएन पर पंक्ति से अभिव्यक्ति का मूल्य) अन्य (सीआरएन-आर एन) (FRN पर पंक्ति के लिए अभिव्यक्ति का मूल्य) (आरएन-एफआरएन) (मूल्य सीआरएन पर पंक्ति के लिए अभिव्यक्ति) पिछली उदाहरण क्वेरी पर विचार करें, जहां हम PERCENTILECONT (0.5) की गणना करते हैं। यहां एन 17 है। पंक्ति संख्या आरएन (1 0.5 (एन -1)) 9 दोनों समूहों के लिए। इसे सूत्र में डालकर, (FRNCRN 9), हम परिणाम के रूप में पंक्ति 9 से मान वापस लौटाते हैं। एक और उदाहरण है, यदि आप PERCENTILECONT (0.66) को गणना करना चाहते हैं। गणना की गई पंक्ति संख्या आरएन (1 0.66 (एन -1)) (1 0.6616) 11.67 PERCENTILECONT (0.66) (12-11.67) (पंक्ति 11 का मान) (11.67-11) (पंक्ति 12 का मान)। ये परिणाम हैं: उलटा प्रतिशतक कुल कार्य अन्य मौजूदा समेकित कार्यों की तरह एक क्वेरी के होने वाले खंड में दिखाई दे सकते हैं। रिपोर्टिंग समुच्चय के रूप में आप कुल कार्य PERCENTILECONT का भी उपयोग कर सकते हैं संपूर्ण कार्य रिपोर्टिंग के रूप में PERCENTILEDISC जब समेकित कार्य रिपोर्टिंग के रूप में उपयोग किया जाता है, तो सिंटैक्स अन्य रिपोर्टिंग समुच्चय के समान होता है यह क्वेरी एक ही चीज़ की गणना करता है (इस परिणाम सेट में ग्राहकों के लिए औसत क्रेडिट सीमा, लेकिन परिणामस्वरूप सेट में हर पंक्ति के परिणाम की रिपोर्ट करता है, जैसा कि निम्नलिखित आउटपुट में दिखाया गया है: PERCENTILEDISC के लिए उलटा प्रतिशतता प्रतिबंध। आदेश द्वारा खंड में अभिव्यक्ति कर सकते हैं किसी भी डेटा प्रकार का हो सकता है जिसे आप क्रमबद्ध कर सकते हैं (संख्यात्मक, स्ट्रिंग, दिनांक, आदि)। हालांकि, ऑर्डर बाय क्लॉज में अभिव्यक्ति एक संख्यात्मक या डेटटाइम प्रकार (अंतराल सहित) होनी चाहिए क्योंकि रेखीय प्रक्षेप का उपयोग PERCENTILECONT के मूल्यांकन के लिए किया जाता है। यदि अभिव्यक्ति प्रकार की है, तो DATE के लिए इंटरपोलेटेड परिणाम छोटी इकाई में गोल किया जाता है। DATE प्रकार के लिए, निकटतम दूसरे (अंतराल दिन के दूसरे) अंतराल प्रकारों के लिए निकटतम दूसरे स्थान पर, या महीने के लिए (इंटरवल साल से महीने)। अन्य समुच्चय की तरह, व्युत्क्रम प्रतिशत्य कार्य परिणाम के मूल्यांकन में NULLs को अनदेखा करते हैं। उदाहरण के लिए, जब आप किसी सेट में औसत मूल्य प्राप्त करना चाहते हैं, तो ओरेकल डाटाबेस एनयूएल की उपेक्षा करता है Ls और गैर-शून्य मानों के बीच औसत दर्जे को पाता है आप ऑर्डर बाय क्लॉज में NULLS FIRST NULLS अंतिम विकल्प का उपयोग कर सकते हैं, लेकिन उन्हें अनदेखा कर दिया जाएगा क्योंकि NULL को अनदेखा कर दिया गया है। हाइफोटीटीकल रैंक और डिस्ट्रिब्यूशन फ़ंक्शंस ये फ़ंक्शन क्या-अगर विश्लेषण के लिए उपयोगी हैं। एक उदाहरण के रूप में, एक पंक्ति का रैंक क्या होगा, यदि पंक्ति को अन्य पंक्तियों के सेट में हाइपरेटिक रूप से सम्मिलित किया गया था, तो समुच्चय का यह परिवार एक लौकिक पंक्ति के एक या एक से अधिक तर्क और पंक्तियों का क्रमबद्ध समूह लेता है, जो रैंक लौटाता है। DENSERANK। पंक्ति के PERCENTRANK या CUMEDIST जैसे कि यह समूह में hypothetically डाला गया था। Hypothetical रैंक और वितरण सिंटैक्स यहाँ, निरंतर अभिव्यक्ति एक अभिव्यक्ति को संदर्भित करती है जो एक निरंतर के लिए मूल्यांकन करती है, और एक से अधिक ऐसी अभिव्यक्तियां हो सकती हैं जो फ़ंक्शन के तर्कों के रूप में दी जाती हैं। ऑर्डर बाय क्लॉज में एक या अधिक एक्स्प्रेशन्स हो सकते हैं जो क्रमबद्ध आदेश को परिभाषित करता है, जिस पर रैंकिंग आधारित होगी। एएससी। DESC। सबसे पहले NULLS अंतिम विकल्प प्रत्येक अभिव्यक्ति के लिए ORDER BY में उपलब्ध होंगे। उदाहरण 21-17 हाइपरेटिकल रैंक और डिस्ट्रिब्यूशन उदाहरण 1 इस खंड में प्रयुक्त उत्पाद तालिका से सूची मूल्य डेटा का उपयोग करके, आप रैंक की गणना कर सकते हैं प्रत्येक स्वेटर उपश्रेणियों के भीतर यह कैसे फिट बैठता है 50 की कीमत के साथ एक काल्पनिक स्वेटर के लिए PERCENTRANK और CUMEDIST क्वेरी और परिणाम हैं: उलटा प्रतिशतक समुच्चय के विपरीत, काल्पनिक रैंक और वितरण कार्यों के लिए क्रमबद्ध विनिर्देशों में आदेश बाय खंड कई अभिव्यक्ति ले सकता है। ऑर्डर बाय क्लॉज में तर्कों और अभिव्यक्तियों की संख्या समान होनी चाहिए और तर्क समान या संगत प्रकार के निरंतर अभिव्यक्ति के साथ क्रमशः ORDER BY अभिव्यक्ति होना चाहिए। निम्नलिखित कई काल्पनिक रैंकिंग कार्यों में दो तर्कों का उपयोग करते हुए एक उदाहरण है। उदाहरण 21-18 हाइफोट्टिक्स रैंक और वितरण उदाहरण 2 ये फ़ंक्शन किसी अन्य समेकित कार्यों की तरह एक क्वेरी के होने वाले खंड में दिखाई दे सकते हैं। वे या तो कुल कार्यों की रिपोर्टिंग या कुल कार्यों को विंडोिंग के रूप में उपयोग नहीं किया जा सकता है रैखिक प्रतिगमन कार्य प्रतिगमन कार्य संख्या-जोड़े के एक सेट में सामान्य-कम-वर्ग प्रतिगमन रेखा के फिटिंग का समर्थन करते हैं। आप उन्हें समेकित कार्य या विंडोिंग या रिपोर्टिंग कार्यों दोनों के रूप में उपयोग कर सकते हैं। कार्यों निम्नानुसार हैं: ओरेकल सभी जोड़े को नष्ट करने के बाद (ई 1। ई 2) के सेट में फ़ंक्शन को लागू करता है जिसके लिए या तो ई 1 या ई 2 का शून्य है। ई 1 को निर्भर चर (एक वाई वैल्यू) के मूल्य के रूप में व्याख्या किया गया है, और ई 2 को स्वतंत्र वैरिएबल (एक एक्स मान) के मान के रूप में व्याख्या किया गया है। दोनों भाव संख्याओं के होने चाहिए। प्रतिगमन कार्यों को सभी डेटा के माध्यम से एक ही पास के दौरान एक साथ गणना की जाती है। उन्हें अक्सर COVARPOP के साथ जोड़ दिया जाता है COVARSAMP। और सीओआरआर कार्य REGRCOUNT फ़ंक्शन REGRCOUNT प्रतिगमन लाइन में फिट करने के लिए उपयोग की गई गैर-शून्य संख्या जोड़े की संख्या देता है। यदि खाली सेट पर लागू होता है (या यदि कोई नहीं (ई 1, ई 2) जोड़े हैं जहां ई 1 या ई 2 का कोई भी नल नहीं है) तो फ़ंक्शन रिटर्न 0. रेग्राजी और रेग्राजीजीएक्स फ़ंक्शन रिएग्राजी और आरएजीआरएजीएक्सएक्स आश्रित वैरिएबल की औसत और स्वतंत्र प्रतिगमन लाइन के चर, क्रमशः। REGRAVGY (E1। E2) जोड़ों को समाप्त करने के बाद अपनी पहली तर्क (ए 1) के औसत की गणना करता है जहां ई 1 या ई 2 का कोई भी शून्य है। इसी तरह, रेग्राजीजीएक्स शून्य उन्मूलन के बाद अपनी दूसरी तर्क (ए 2) के औसत की गणना करता है रिक्त सेट पर लागू होने पर दोनों फ़ंक्शन शून्य पर लौटें। REGRSLOPE और REGRINTERCEPT फ़ंक्शंस REGRSLOPE फ़ंक्शन गैर-नल (e1। E2) जोड़े से युक्त प्रतिगमन लाइन के ढलान को मापता है। REGRINTERCEPT फ़ंक्शन प्रतिगमन रेखा के वाई-इंटरसेप्ट को मापता है। जब भी ढलान या प्रतिगमन औसत नल होते हैं, तब रिग्रिन्टरपीटी रिटर्न मिलता है। REGRR2 फ़ंक्शन REGRR2 फ़ंक्शन प्रतिगमन लाइन के लिए निर्धारण के गुणांक (आमतौर पर आर-स्क्वेयर या फिट की भलाई) को गणना करता है आरजीआरआर 2 0 और 1 के बीच के मूल्यों को रिटर्न करते हैं जब प्रतिगमन लाइन परिभाषित की जाती है (रेखा का ढलान शून्य नहीं है), और यह नल अन्यथा देता है करीब मूल्य 1 है, बेहतर प्रतिगमन लाइन डेटा फिट बैठता है। REGRSXX, REGRSYY, और REGRSXY फ़ंक्शन REGRSXX रीग्रेसिअल और आरईजीआरएससीवाई फ़ंक्शन का उपयोग प्रतिगमन विश्लेषण के लिए विभिन्न नैदानिक ​​आंकड़ों के कंप्यूटिंग में किया जाता है। (ई 1। ए 2) जोड़े को खत्म करने के बाद जहां ई 1 या ई 2 का कोई भी शून्य है, ये फ़ंक्शंस निम्न कम्प्यूटेशन्स बनाते हैं: रैखिक पुनरावृत्ति सांख्यिकी उदाहरण कुछ सामान्य नैदानिक ​​आंकड़े जो रेखीय प्रतिगमन विश्लेषण के साथ तालिका 21-2, सामान्य नैदानिक ​​सांख्यिकी और उनके भाव ध्यान दें कि यह नई प्रकार्यों को रिलीज़ करता है ताकि आप इन सभी को गणना कर सकें। तालिका 21-2 सामान्य नैदानिक ​​आंकड़े और उनकी अभिव्यक्तियाँ नमूना लीनियर प्रतिगमन गणना इस उदाहरण में, हम एक साधारण-कम-वर्ग प्रतिगमन लाइन की गणना करते हैं जो उत्पाद सूची मूल्य के एक रैखिक फ़ंक्शन के रूप में उत्पाद की मात्रा को व्यक्त करती है। गणना बिक्री चैनल द्वारा समूहीकृत की जाती है। मूल्य SLOPE INTCPT। आरएसक्यूआर क्रमशः ढलान, अवरोधन, और प्रतिगमन लाइन के निर्धारण का गुणांक है। (पूर्णांक) मान COUNT प्रत्येक चैनल में उत्पादों की संख्या है जिसके लिए दोनों मात्रा में बेचा और सूची मूल्य डेटा उपलब्ध हैं। बार-बार आइटमों को देखते हुए कि कितनी बार दी गई घटना होती है (उदाहरण के लिए, कितनी बार किसी ने किराने पर दूध खरीदा है), अक्सर मदों की गिनती के लिए एक तंत्र प्रदान करता है कि कितनी बार कई घटनाएं एक साथ होती हैं (उदाहरण के लिए, कितनी बार किसी ने दोनों दूध खरीदा है और किराने की दुकान पर एक साथ अनाज)। अक्सर-आइटमों के संचालन के लिए इनपुट डेटा का एक सेट होता है जो आइटमों के संग्रह (आइटमसेट) का प्रतिनिधित्व करता है। मदों के कुछ उदाहरण सभी उत्पाद हो सकते हैं, जो किसी दिए गए ग्राहक को किराने की दुकान (आमतौर पर एक बाज़ार की टोकरी कहा जाता है), एक वेब पेज या किसी एक सत्र में उपयोग किए जाने वाले वेब पृष्ठों या वित्तीय सेवाओं में एक यात्रा में खरीदा जाता था। दी ग्राहक अक्सर आइटम्सट की धारणा उन आइटम्स को ढूंढना है जो सबसे अधिक बार होती हैं अगर आप लगातार-मदों के ऑपरेटर को किराने की दुकानों के पॉइंट-ऑफ-सेल डेटा पर लागू करते हैं, तो आप शायद, पता लगा सकते हैं कि दूध और केले आइटम की सबसे अधिक खरीदी गई जोड़ी है। इस प्रकार व्यापारिक खुफिया वातावरणों में कई वर्षों से लगातार आइटमों का उपयोग किया जाता है, साथ ही खुदरा उद्योग में बाज़ार की टोकरी के विश्लेषण के लिए सबसे आम बात है। लगातार आइटमों को डेटाबेस के साथ एकीकृत किया जाता है, जो संबंधपरक तालिकाओं के शीर्ष पर कार्य करता है और एसक्यूएल के माध्यम से पहुंचा जाता है। यह एकीकरण कुछ महत्वपूर्ण लाभ प्रदान करता है: पहले से आईआईएसईटी संचालन पर भरोसा रखने वाले आवेदन अब काफी सुधरे हुए प्रदर्शन और सरल कार्यान्वयन से लाभ प्राप्त करते हैं। एसक्यूएल-आधारित अनुप्रयोग जो पहले से लगातार आइटमों का उपयोग नहीं करते थे अब आसानी से इस कार्यक्षमता का लाभ उठाने के लिए बढ़ाया जा सकता है। बार-बार आइटम्स विश्लेषण विश्लेषण PLSQL पैकेज DBMSFREQUENTITEMSETS के साथ किया जाता है। अधिक जानकारी के लिए PLSQL संकुल और प्रकार संदर्भ देखें अन्य सांख्यिकीय फ़ंक्शंस ओरेकल एसक्यूएल सांख्यिकीय कार्यों का एक सेट और एक आंकड़े पैकेज, डीबीएमएसएसटीएटीएफ़एएनएसीएस। This section lists some of the new functions along with basic syntax. See PLSQL Packages and Types Reference for detailed information about the DBMSSTATFUNCS package and Oracle Database SQL Reference for syntax and semantics. Descriptive Statistics You can calculate the following descriptive statistics: Median of a Data Set Mode of a Data Set You can calculate the following parametric statistics: Spearmans rho Coefficient Kendalls tau-b Coefficient In addition to the functions, this release has a new PLSQL package, DBMSSTATFUNCS. It contains the descriptive statistical function SUMMARY along with functions to support distribution fitting. The SUMMARY function summarizes a numerical column of a table with a variety of descriptive statistics. The five distribution fitting functions support normal, uniform, Weibull, Poisson, and exponential distributions. WIDTHBUCKET Function For a given expression, the WIDTHBUCKET function returns the bucket number that the result of this expression will be assigned after it is evaluated. You can generate equiwidth histograms with this function. Equiwidth histograms divide data sets into buckets whose interval size (highest value to lowest value) is equal. The number of rows held by each bucket will vary. A related function, NTILE. creates equiheight buckets. Equiwidth histograms can be generated only for numeric, date or datetime types. So the first three parameters should be all numeric expressions or all date expressions. Other types of expressions are not allowed. If the first parameter is NULL. the result is NULL. If the second or the third parameter is NULL. an error message is returned, as a NULL value cannot denote any end point (or any point) for a range in a date or numeric value dimension. The last parameter (number of buckets) should be a numeric expression that evaluates to a positive integer value 0, NULL. or a negative value will result in an error. Buckets are numbered from 0 to ( n 1). Bucket 0 holds the count of values less than the minimum. Bucket( n 1) holds the count of values greater than or equal to the maximum specified value. WIDTHBUCKET Syntax The WIDTHBUCKET takes four expressions as parameters. The first parameter is the expression that the equiwidth histogram is for. The second and third parameters are expressions that denote the end points of the acceptable range for the first parameter. The fourth parameter denotes the number of buckets. Consider the following data from table customers. that shows the credit limits of 17 customers. This data is gathered in the query shown in Example 21-19 . In the table customers. the column custcreditlimit contains values between 1500 and 15000, and we can assign the values to four equiwidth buckets, numbered from 1 to 4, by using WIDTHBUCKET (custcreditlimit, 0, 20000, 4). Ideally each bucket is a closed-open interval of the real number line, for example, bucket number 2 is assigned to scores between 5000.0000 and 9999.9999. sometimes denoted 5000, 10000) to indicate that 5,000 is included in the interval and 10,000 is excluded. To accommodate values outside the range 0, 20,000), values less than 0 are assigned to a designated underflow bucket which is numbered 0, and values greater than or equal to 20,000 are assigned to a designated overflow bucket which is numbered 5 (num buckets 1 in general). See Figure 21-3 for a graphical illustration of how the buckets are assigned. You can specify the bounds in the reverse order, for example, WIDTHBUCKET ( custcreditlimit. 20000. 0. 4 ). When the bounds are reversed, the buckets will be open-closed intervals. In this example, bucket number 1 is ( 15000,20000 , bucket number 2 is ( 10000,15000 , and bucket number 4, is ( 0 ,5000. The overflow bucket will be numbered 0 ( 20000. infinity ), and the underflow bucket will be numbered 5 (- infinity. 0 . It is an error if the bucket count parameter is 0 or negative. The followin g query shows the bucket numbers for the credit limits in the customers table for both cases where the boundaries are specified in regular or reverse order. We use a range of 0 to 20,000. User-Defined Aggregate Functions Oracle offers a facility for creating your own functions, called user-defined aggregate functions. These functions are written in programming languages such as PLSQL, Java, and C, and can be used as analytic functions or aggregates in materialized views. See Oracle Data Cartridge Developers Guide for further information regarding syntax and restrictions. The advantages of these functions are: Highly complex functions can be programmed using a fully proced ural language. Higher scalability than other techniques when user-defined functions are programmed for parallel processing. Object datatypes can be processed. As a simple example of a user-defined aggregate function, consider the skew statistic. This calculation measures if a data set has a lopsided distribution about its mean. It will tell you if one tail of the distribution is significantly larger than the other. If you created a user-defined aggregate called udskew and applied it to the credit limit data in the prior example, the SQL statement and results might look like this: Before building user-defined aggregate functions, you should consider if your needs can be met in regular SQL. Many complex calculations are possible directly in SQL, particularly by using the CASE expression. Staying with regular SQL will enable simpler development, and many query operations are already well-parallelized in SQL. Even the earlier example, the skew statistic, can be created using standard, albeit lengthy, SQL. CASE Expressions Oracle now supports simple and searched CASE statements. CASE statements are similar in purpose to the DECODE statement, but they offer more flexibility and logical power. They are also easier to read than traditional DECODE statements, and offer better performance as well. They are commonly used when breaking categories into buckets like age (for example, 20-29, 30-39, and so on). The syntax for simple statements is: The syntax for searched statements is: You can specify only 255 arguments and each WHEN. THEN pair counts as two arguments. For a workaround to this limit, see Oracle Database SQL Reference . Suppose you wanted to find the average salary of all employees in the company. If an employees salary is less than 2000, you want the query to use 2000 instead. Without a CASE statement, you would have to write this query as follows, In this, foo is a function that returns its input if the input is greater than 2000, and returns 2000 otherwise. The query has performance implications because it needs to invoke a function for each row. Writing custom functions can also add to the development load. Using CASE expressions in the database without PLSQL, this query can be rewritten as: Using a CASE expression lets you avoid developing custom functions and can also perform faster. Creating Histograms With User-Defined Buckets You can use the CASE statement when you want to obtain histograms with user-defined buckets (both in number of buckets and width of each bucket). The following are two examples of histograms created with CASE statements. In the first example, the histogram totals are shown in multiple columns and a single row is returned. In the second example, the histogram is shown with a label column and a single column for totals, and multiple rows are returned. Example 21-21 Histogram Example 1 Example 21-22 Histogram Example 2 Data Densification for Reporting Data is normally stored in sparse form. That is, if no value exists for a given combination of dimension values, no row exists in the fact table. However, you may want to view the data in dense form, with rows for all combination of dimension values displayed even when no fact data exist for them. For example, if a product did not sell during a particular time period, you may still want to see the product for that time period with zero sales value next to it. Moreover, time series calculations can be performed most easily when data is dense along the time dimension. This is because dense data will fill a consistent number of rows for each period, which in turn makes it simple to use the analytic windowing functions with physical offsets. Data densification is the process of converting spare data into dense form. To overcome the problem of sparsity, you can use a partitioned outer join to fill the gaps in a time series or any other dimension. Such a join extends the conventional outer join syntax by applying the outer join to each logical partition defined in a query. Oracle logically partitions the rows in your query based on the expression you specify in the PARTITION BY clause. The result of a partitioned outer join is a UNION of the outer joins of each of the partitions in the logically partitioned table with the table on the other side of the join. Note that you can use this type of join to fill the gaps in any dimension, not just the time dimension. Most of the examples here focus on the time dimension because it is the dimension most frequently used as a basis for comparisons. Partition Join Syntax The syntax for partitioned outer join extends the ANSI SQL JOIN clause with the phrase PARTITION BY followed by an expression list. The expressions in the list specify the group to which the outer join is applied. The following are the two forms of syntax normally used for partitioned outer join: Note that FULL OUTER JOIN is not supported with a partitioned outer join. Sample of Sparse Data A typi cal situation with a sparse dimension is shown in the following example, which computes the weekly sales and year-to-date sales for the product Bounce for weeks 20-30 in 2000 and 2001: In this example, we would expect 22 rows of data (11 weeks each from 2 years) if the data were dense. However we get only 18 rows because weeks 25 and 26 are missing in 2000, and weeks 26 and 28 in 2001. Filling Gaps in Data We can take the sparse data of the preceding query and do a partitioned outer join with a dense set of time data. In the following query, we alias our original query as v and we select data from the times table, which we alias as t. Here we retrieve 22 rows because there are no gaps in the series. The four added rows each have 0 as their Sales value set to 0 by using the NVL function. Note that in this query, a WHERE condition was placed for weeks between 20 and 30 in the inline view for the time dimension. This was introduced to keep the result set small. Filling Gaps in Two Dimensions N-dimensional data is typically displayed as a dense 2-dimensional cross tab of (n - 2) page dimensions. This requires that all dimension values for the two dimensions appearing in the cross tab be filled in. The following is another example where the partitioned outer join capability can be used for filling the gaps on two dimensions: In this query, the WITH sub-query factoring clause v1. summarizes sales data at the product, country, and year level. This result is sparse but users may want to see all the country, year combinations for each product. To achieve this, we take each partition of v1 based on product values and outer join it on the country dimension first. This will give us all values of country for each product. We then take that result and partition it on product and country values and then outer join it on time dimension. This will give us all time values for each product and country combination. Filling Gaps in an Inventory Table An inventory table typically tracks quantity of units available for various products. This table is sparse: it only stores a row for a product when there is an event. For a sales table, the event is a sale, and for the inventory table, the event is a change in quantity available for a product. For example, consider the following inventory table: The inventory table now has the following rows: For reporting purposes, users may want to see this inventory data differently. For example, they may want to see all values of time for each product. This can be accomplished using partitioned outer join. In addition, for the newly inserted rows of missing time periods, users may want to see the values for quantity of units column to be carried over from the most recent existing time period. The latter can be accomplished using analytic window function LASTVALUE value. Here is the query and the desired output: The inner query computes a partitioned outer join on time within each product. The inner query densifies the data on the time dimension (meaning the time dimension will now have a row for each day of the week). However, the measure column quantity will have nulls for the newly added rows (see the output in the column quantity in the following results. The outer query uses the analytic function LASTVALUE. Applying this function partitions the data by product and orders the data on the time dimension column ( timeid ). For each row, the function finds the last non-null value in the window due to the option IGNORE NULLS. which you can use with both LASTVALUE and FIRSTVALUE. We see the desired output in the column repeatedquantity in the following output: Computing Data Values to Fill Gaps Examples in previous section illustrate how to use partitioned outer join to fill gaps in one or more dimensions. However, the result sets produced by partitioned outer join have null values for columns that are not included in the PARTITION BY list. Typically, these are measure columns. Users can make use of analytic SQL functions to replace those null values with a non-null value. For example, the following q uery computes monthly totals for products 64MB Memory card and DVD-R Discs (product IDs 122 and 136) for the year 2000. It uses partitioned outer join to densify data for all months. For the missing months, it then uses the analytic SQL function AVG to compute the sales and units to be the average of the months when the product was sold. If working in SQLPlus, the following two commands will wrap the column headings for greater readability of results: Time Series Calculations on Densified Data Densificatio n is not just for reporting purpose. It also enables certain types of calculations, especially, time series calculations. Time series calculations are easier when data is dense along the time dimension. Dense data has a consistent number of rows for each time periods which in turn make it simple to use analytic window functions with physical offsets. To illustrate, lets first take the example on Filling Gaps in Data. and lets add an analytic function to that query. In the following enhanced version, we calculate weekly year-to-date sales alongside the weekly sales. The NULL values that the partitioned outer join inserts in making the time series dense are handled in the usual way: the SUM function treats them as 0s. Period-to-Period Comparison for One Time Level: Example How do we use this feature to compare values across time periods Specifically, how do we calculate a year-over-year sales comparison at the week level The following query returns on the same row, for each product, the year-to-date sales for each week of 2001 with that of 2000. Note that in this example we start with a WITH clause. This improves readability of the query and lets us focus on the partitioned outer join. If working in SQLPlus, the following command will wrap the column headings for greater readability of results: In the FROM clause of the in-line view densesales. we use a partitioned outer join of aggregate view v and time view t to fill gaps in the sales data along the time dimension. The output of the partitioned outer join is then processed by the analytic function SUM. OVER to compute the weekly year-to-date sales (the weeklyytdsales column). Thus, the view densesales computes the year-to-date sales data for each week, including those missing in the aggregate view s. The in-line view yearoveryearsales then computes the year ago weekly year-to-date sales using the LAG function. The LAG function labeled weeklyytdsalesprioryear specifies a PARTITION BY clause that pairs rows for the same week of years 2000 and 2001 into a single partition. We then pass an offset of 1 to the LAG function to get the weekly year to date sales for the prior year. The outermost query block selects data from yearoveryearsales with the condition yr 2001, and thus the query returns, for each product, its weekly year-to-date sales in the specified weeks of years 2001 and 2000. Period-to-Period Comparison for Multiple Time Levels: Example While the prior example shows us a way to create comparisons for a single time level, it would be even more useful to handle multiple time levels in a single query. For example, we could compare sales versus the prior period at the year, quarter, month and day levels. How can we create a query which performs a year-over-year comparison of year-to-date sales for all levels of our time hierarchy We will take several steps to perform this task. The goal is a single query with comparisons at the day, week, month, quarter, and year level. The steps are as follows: We will create a view called cubeprodtime. which holds a hierarchical cube of sales aggregated across times and products . Then we will create a view of the time dimension to use as an edge of the cube. The time edge, which holds a complete set of dates, will be partitioned outer joined to the sparse data in the view cubeprodtime . Finally, for maximum performance, we will create a materialized view, mvprodtime. built using the same definition as cubeprodtime . For more information regarding hierarchical cubes, see Chapter 20, SQL for Aggregation in Data Warehouses. The materialized view is defined using the following statement: Step 1 Create the hierarchical cube view The materialized view shown in the following may already exist in your system if not, create it now. If you must generate it, please note that we limit the query to just two products to keep processing time short: Because this view is limited to two products, it returns just over 2200 rows. Note that the column HierarchicalTime contains string representations of time from all levels of the time hierarchy. The CASE expression used for the HierarchicalTime column appends a marker (0, 1. ) to each date string to denote the time level of the value. A 0 represents the year level, 1 is quarters, 2 is months, and 3 is day. Note that the GROUP BY clause is a concatenated ROLLUP which specifies the rollup hierarchy for the time and product dimensions. The GROUP BY clause is what determines the hierarchical cube contents. Step 2 Create the view edgetime, which is a complete set of date values edgetime is the source for filling time gaps in the hierarchical cube using a partitioned outer join. The column HierarchicalTime in edgetime will be used in a partitioned join with the HierarchicalTime column in the view cubeprodtime. The following statement defines edgetime : Step 3 Create the materialized view mvprodtime to support faster performance The materialized view definition is a duplicate of the view cubeprodtime defined earlier. Because it is a duplicate query, references to cubeprodtime will be rewritten to use the mvprodtime materialized view. The following materialized may already exist in your system if not, create it now. If you must generate it, please note that we limit the query to just two products to keep processing time short. Step 4 Create the comparison query We have now set the stage for our comparison query. We can obtain period-to-period comparison calculations at all time levels. It requires applying analytic functions to a hierarchical cube with dense data along the time dimension. Some of the calculations we can achieve for each time level are: Sum of sales for prior period at all levels of time. Variance in sales over prior period. Sum of sales in the same period a year ago at all levels of time. Variance in sales over the same period last year. The following example performs all four of these calculations. It uses a partitioned outer join of the views cubeprodtime and edgetime to create an in-line view of dense data called densecubeprodtime. The query then uses the LAG function in the same way as the prior single-level example. The outer WHERE clause specifies time at three levels: the days of August 2001, the entire month, and the entire third quarter of 2001. Note that the last two rows of the results contain the month level and quarter level aggregations. Note: To make the results easier to read if you are using SQLPlus, the column headings should be adjusted with the following commands. The commands will fold the column headings to reduce line length: Here is the query comparing current sales to prior and year ago sales: The first LAG function ( salespriorperiod ) partitions the data on gidp. cat. subcat. prod. gidt and orders the rows on all the time dimension columns. It gets the sales value of the prior period by passing an offset of 1. The second LAG function ( salessameperiodprioryear ) partitions the data on additional columns qtrnum. monnum. and daynum and orders it on yr so that, with an offset of 1, it can compute the year ago sales for the same period. The outermost SELECT clause computes the variances. Creating a Custom Member in a Dimension: Example In many OLAP tasks, it is helpful to define custom members in a dimension. For instance, you might define a specialized time period for analyses. You can use a partitioned outer join to temporarily add a member to a dimension. Note that the new SQL MODEL clause is suitable for creating more complex scenarios involving new members in dimensions. See Chapter 22, SQL for Modeling for more information on this topic. As an example of a task, what if we want to define a new member for our time dimension We want to create a 13th member of the Month level in our time dimension. This 13th month is defined as the summation of the sales for each product in the first month of each quarter of year 2001. The solution has two steps. Note that we will build this solution using the views and tables created in the prior example. Two steps are required. First, create a view with the new member added to the appropriate dimension. The view uses a UNION ALL operation to add the new member. To query using the custom member, use a CASE expression and a partitioned outer join. Our new member for the time dimension is created with the following view: In this statement, the view timec is defined by performing a UNION ALL of the edgetime view (defined in the prior example) and the user-defined 13th month. The gidt value of 8 was chosen to differentiate the custom member from the standard members. The UNION ALL specifies the attributes for a 13th month member by doing a SELECT from the DUAL table. Note that the grouping id, column gidt. is set to 8, and the quarter number is set to 5. Then, the second step is to use an inline view of the query to perform a partitioned outer join of cubeprodtime with timec. This step creates sales data for the 13th month at each level of product aggregation. In the main query, the analytic function SUM is used with a CASE expression to compute the 13th month, which is defined as the summation of the first months sales of each quarter. The SUM function uses a CASE to limit the data to months 1, 4, 7, and 10 within each year. Due to the tiny data set, with just 2 products, the rollup values of the results are necessarily repetitions of lower level aggregations. For more realistic set of rollup values, you can include more products from the Game Console and Y Box Games subcategories in the underlying materialized view.

No comments:

Post a Comment