The document discusses a SQL query that calculates the average product quality for sequential groups of the same product in a table.
The table contains product test data with a batch number, product code, and quality score. The query uses self joins to group batches of the same product together, and then calculates the average quality for each group.
It provides the sample data, the full SQL query, and step-by-step explanations of how the query works. The goal is to group contiguous batches of the same product together, while treating batches that are not contiguous as separate groups.
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...Mark Wong
Third presentation in a speaker series sponsored by the Portland State University Computer Science Department. The series covers PostgreSQL performance with an OLTP (on-line transaction processing) workload called Database Test 2 (DBT-2). This presentation go into detail about what the workload does.
New Tuning Features in Oracle 11g - How to make your database as boring as po...Sage Computing Services
One of the key problems that have haunted Oracle sites since the introduction of the cost based optimiser is the ability to provide a stable level of performance over time. The very responsiveness of the CBO to factors such as changes in statistics and initialisation parameters can lead to sudden changes in performance levels. Oracle 11g is set to introduce a number of features that will assist the DBA in providing a stable environment for mission critical applications. Excitement is for out of work time, (and for developers). The aim of most database administrators is to have as boring a working life as possible. Oracle 11g may help us achieve those aims.
This presentation discusses some of those features including:
Capture and replay of workload
Automatic SGA tuning
Managing and fixing plans
The 11g Automatic Tuning Advisor
Optimizer in oracle 11g by wwf from ebay COCLouis liu
The document discusses new features in Oracle 11g related to optimizer statistics. It describes enhancements to auto_sample_size that improve accuracy and performance. It also discusses how 11g optimizer can better estimate selectivity for multi-column indexes by using distinct values, rather than just dividing by individual column counts. Extended statistics are introduced to capture column correlations, allowing more accurate cardinality estimates.
This document discusses multiple-column subqueries in SQL. It describes how multiple-column subqueries can return multiple columns that can then be compared pairwise or nonpairwise to columns in the outer query. Examples are provided of multiple-column subqueries used to return order items that match the product number and quantity from another order. The document also discusses how subqueries can be used in the FROM clause and how null values are handled in subqueries.
The document discusses database management systems and database concepts. It defines what a database is and reasons for using databases. It covers different data models including the relational, object-oriented relational, and semi-structured models. It also discusses defining database schemas in SQL, various relational operations like selection and projection, and different types of joins. Finally, it covers topics related to database normalization including anomalies that can occur without normalization and the first normal form.
Using PostgreSQL statistics to optimize performance Alexey Ermakov
The document discusses using statistics in PostgreSQL to optimize performance. It describes how the planner estimates row counts in tables and selectivity of query conditions. Default estimators are used if no statistics are collected. Statistics are gathered on tables and indexes to estimate selectivity. Partial indexes can be useful when not all values need to be indexed. Monitoring and diagnosing performance issues is also covered.
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADataconomy Media
Making the data of a company accessible to analysts, business users and data scientists can be a quite painful endeavor. In the past 5 years, Project A has supported many of its portfolio companies with building data infrastructures and we experienced many of these pains first-hand. This talk shows how some of these pains can be overcome by applying common sense and standard software engineering best practices.
The document describes several databases related to banking, insurance, orders, students, and books. It includes the structure of each database with table definitions and sample data. Various SQL queries are demonstrated to retrieve, update, insert and delete records in the tables to solve business problems for each database application.
PostgreSQL Portland Performance Practice Project - Database Test 2 Workload D...Mark Wong
Third presentation in a speaker series sponsored by the Portland State University Computer Science Department. The series covers PostgreSQL performance with an OLTP (on-line transaction processing) workload called Database Test 2 (DBT-2). This presentation go into detail about what the workload does.
New Tuning Features in Oracle 11g - How to make your database as boring as po...Sage Computing Services
One of the key problems that have haunted Oracle sites since the introduction of the cost based optimiser is the ability to provide a stable level of performance over time. The very responsiveness of the CBO to factors such as changes in statistics and initialisation parameters can lead to sudden changes in performance levels. Oracle 11g is set to introduce a number of features that will assist the DBA in providing a stable environment for mission critical applications. Excitement is for out of work time, (and for developers). The aim of most database administrators is to have as boring a working life as possible. Oracle 11g may help us achieve those aims.
This presentation discusses some of those features including:
Capture and replay of workload
Automatic SGA tuning
Managing and fixing plans
The 11g Automatic Tuning Advisor
Optimizer in oracle 11g by wwf from ebay COCLouis liu
The document discusses new features in Oracle 11g related to optimizer statistics. It describes enhancements to auto_sample_size that improve accuracy and performance. It also discusses how 11g optimizer can better estimate selectivity for multi-column indexes by using distinct values, rather than just dividing by individual column counts. Extended statistics are introduced to capture column correlations, allowing more accurate cardinality estimates.
This document discusses multiple-column subqueries in SQL. It describes how multiple-column subqueries can return multiple columns that can then be compared pairwise or nonpairwise to columns in the outer query. Examples are provided of multiple-column subqueries used to return order items that match the product number and quantity from another order. The document also discusses how subqueries can be used in the FROM clause and how null values are handled in subqueries.
The document discusses database management systems and database concepts. It defines what a database is and reasons for using databases. It covers different data models including the relational, object-oriented relational, and semi-structured models. It also discusses defining database schemas in SQL, various relational operations like selection and projection, and different types of joins. Finally, it covers topics related to database normalization including anomalies that can occur without normalization and the first normal form.
Using PostgreSQL statistics to optimize performance Alexey Ermakov
The document discusses using statistics in PostgreSQL to optimize performance. It describes how the planner estimates row counts in tables and selectivity of query conditions. Default estimators are used if no statistics are collected. Statistics are gathered on tables and indexes to estimate selectivity. Partial indexes can be useful when not all values need to be indexed. Monitoring and diagnosing performance issues is also covered.
DN 2017 | Reducing pain in data engineering | Martin Loetzsch | Project ADataconomy Media
Making the data of a company accessible to analysts, business users and data scientists can be a quite painful endeavor. In the past 5 years, Project A has supported many of its portfolio companies with building data infrastructures and we experienced many of these pains first-hand. This talk shows how some of these pains can be overcome by applying common sense and standard software engineering best practices.
The document describes several databases related to banking, insurance, orders, students, and books. It includes the structure of each database with table definitions and sample data. Various SQL queries are demonstrated to retrieve, update, insert and delete records in the tables to solve business problems for each database application.
Managing Statistics for Optimal Query PerformanceKaren Morton
Half the battle of writing good SQL is in understanding how the Oracle query optimizer analyzes your code and applies statistics in order to derive the “best” execution plan. The other half of the battle is successfully applying that knowledge to the databases that you manage. The optimizer uses statistics as input to develop query execution plans, and so these statistics are the foundation of good plans. If the statistics supplied aren’t representative of your actual data, you can expect bad plans. However, if the statistics are representative of your data, then the optimizer will probably choose an optimal plan.
This document presents a comparison of a modified 64-bit binary comparator design and an existing 64-bit binary comparator design. The modified design implements the first stage using CMOS logic instead of pass transistor logic to improve speed. Simulation results show the modified design has a 0.47% reduction in delay for the A_LT_B output and a 1.23% reduction in delay for the A_EQU_B output compared to the existing design, while using more power and transistors. Therefore, the modified design provides better performance for high-speed applications.
High speed tree-based 64-bit cmos binary comparatoreSAT Journals
Abstract A high-speed tree-based 64-bit CMOS binary comparator is proposed in this brief. Comparison is most basic arithmetic operation that determines if one number is greater than, equal to, or less than the other number. Comparator is most fundamental component that performs comparison operation. This brief presents comparison of modified and existing 64-bit binary comparator designs concentrating on delay. Means some modifications are done in existing 64-bit binary comparator design to improve the speed of the circuit. Comparison between modified and existing 64-bit binary comparator designs is calculated by simulation that is performed at 90nm technology in Tanner EDA Tool. Index Terms: Binary comparator, digital arithmetic, high-speed
The document summarizes how SQL Plan Directives in Oracle 12c can help address issues caused by cardinality misestimation in the optimizer. It provides an example where the optimizer underestimates the number of rows returned by a query on a table due to not having statistics on correlated columns. In 12c, a SQL Plan Directive is automatically generated after the first execution to capture this misestimation. On subsequent queries, the directive can be used to provide more accurate cardinality estimates through automatic reoptimization or dynamic sampling.
Informix Warehouse Accelerator (IWA) features in version 12.1Keshav Murthy
The document discusses enhancements made to Informix Warehouse Accelerator (IWA) in version 12.10. Key points include:
- IWA now supports operations like creating, deploying, loading, enabling, and disabling data marts on secondary nodes in MACH11 and high availability environments, in addition to the primary/standard server node.
- New procedures like dropPartMart and loadPartMart allow refreshing partitions in a partitioned fact table within a data mart.
- Performance of SQL queries involving UNIONs, derived tables, and DISTINCT aggregates was improved.
- Additional OLAP functions and options like NULLS FIRST/LAST in ORDER BY were added for enhanced analytical querying.
This document discusses various Oracle SQL concepts including query optimization, execution plans, joins, indexes, and full table scans. It provides guidance on understanding how Oracle processes and executes SQL queries, the importance of statistics and selectivity, and techniques for writing efficient queries such as predicate pushing and query transformations. The goal is to help readers gain a conceptual understanding of Oracle's internals to formulate more efficient SQL.
The document discusses Exadata Smart Scan, which offloads SQL processing from the database layer to the storage cell layer. Smart Scan passes only the required data blocks filtered by predicates to the database server instead of all blocks. Testing shows that with Smart Scan, a count query takes 0.05 seconds versus 15.68 seconds without Smart Scan. Analysis of statistics with Smart Scan shows most blocks are filtered at the storage layer with only a small amount of data, about 0.18MB, returned to the database layer.
Introduce Brainf*ck, another Turing complete programming language. Then, try to implement the following from scratch: Interpreter, Compiler [x86_64 and ARM], and JIT Compiler.
The document discusses Test4pass, an expert in IT certification exams. It lists popular IT certifications from Microsoft, Cisco, IBM, and CompTIA and provides sample exam questions and answers related to Microsoft SQL Server 2008 database development.
This document provides an overview of PostgreSQL topics including:
- Installation and configuration best practices such as using package management and configuring logging
- Routine maintenance activities like vacuuming and backups
- Upgrades and the differences between major, minor, and bugfix versions
- Advanced SQL topics like window functions, common table expressions, and querying slow queries
Big Data Analytics with MariaDB ColumnStoreMariaDB plc
MariaDB ColumnStore is an open source columnar database storage engine that provides high performance analytics capabilities on large datasets using standard SQL. It uses a distributed architecture that stores data by column rather than by row to enable fast queries by only accessing the relevant columns. It can scale horizontally on commodity servers to support analytics workloads on datasets ranging from millions to trillions of rows.
The document provides an overview of execution plans in SQL Server and what aspects to examine. It discusses the key stages in the execution process including parsing, optimization, and execution. Specific operators like nested loops, hash matches, and parallelism are also covered. The document is intended to help beginners understand execution plans and what aspects provide useful information for troubleshooting query performance issues.
An overview presentation covering the use of Oracle's PX functionality including some tips and traps. Detailed white paper at http://oracledoug.com/px.html
The optimizer is the "brain" of the database, interpreting SQL queries and determining the fastest method of execution. In this talk by Bruce Momjian, Senior Database Architect at EnterpriseDB and co-founder of the PostgreSQL Global Development Group, uses the explain command to show how the optimizer interprets queries and determines optimal execution. The talk aimed at assisting developers and administrators in understanding how Postgres optimally executes their queries and what steps they can take to understand and perhaps improve its behavior.
Automated parameter optimization techniques like Caret can substantially improve the performance of defect prediction models over using default parameter settings. When applied to 18 datasets using 26 classification techniques, Caret optimized models improved average AUC performance by up to 40 percentage points for some techniques. Caret optimized models also tended to be more stable than default models, with the stability ratio being lower than 1 for 35% of techniques studied. Overall, automated parameter optimization can significantly enhance both the performance and stability of defect prediction models.
GSP 215 RANK Become Exceptional--gsp215rank.comclaric119
FOR MORE CLASSES VISIT
www.gsp215rank.com
Please check all Included Assignment Details below
GSP 215 Week 1 Homework Command Line in Windows and Linux
GSP 215 Week 2 iLab Binary Representation of Information
GSP 215 Week 2 Homework Representing and Manipulating Information
FOR MORE CLASSES VISIT
www.gsp215rank.com
Please check all Included Assignment Details below
GSP 215 Week 1 Homework Command Line in Windows and Linux
GSP 215 Week 2 iLab Binary Representation of Information
GSP 215 Week 2 Homework Representing and Manipulating Information
The document discusses how database optimizers can sometimes provide incorrect cardinality estimates that result in inefficient query plans. It provides four examples of cardinality errors caused by uneven data distributions. The key strategies for addressing cardinality problems are: 1) giving the optimizer more statistical information through histograms and SQL profiles, 2) overriding optimizer decisions with hints, and 3) changing the application design/data model. Providing more information to the optimizer usually improves plans without additional code changes.
This document contains a midterm exam for an Elements of Programming course. It consists of 4 sections - multiple choice, fill in the blank, short answer, and programming questions. The multiple choice and fill in the blank sections contain 10 questions each worth 1 mark each. The short answer section contains 3 questions worth a total of 40 marks. The programming question is worth 25 marks and requires the student to create a C++ program to simulate a vending machine. The exam is worth a total of 100 marks and students are instructed to answer all questions and show all working.
Learn SQL from basic queries to Advance queriesmanishkhaire30
Dive into the world of data analysis with our comprehensive guide on mastering SQL! This presentation offers a practical approach to learning SQL, focusing on real-world applications and hands-on practice. Whether you're a beginner or looking to sharpen your skills, this guide provides the tools you need to extract, analyze, and interpret data effectively.
Key Highlights:
Foundations of SQL: Understand the basics of SQL, including data retrieval, filtering, and aggregation.
Advanced Queries: Learn to craft complex queries to uncover deep insights from your data.
Data Trends and Patterns: Discover how to identify and interpret trends and patterns in your datasets.
Practical Examples: Follow step-by-step examples to apply SQL techniques in real-world scenarios.
Actionable Insights: Gain the skills to derive actionable insights that drive informed decision-making.
Join us on this journey to enhance your data analysis capabilities and unlock the full potential of SQL. Perfect for data enthusiasts, analysts, and anyone eager to harness the power of data!
#DataAnalysis #SQL #LearningSQL #DataInsights #DataScience #Analytics
Managing Statistics for Optimal Query PerformanceKaren Morton
Half the battle of writing good SQL is in understanding how the Oracle query optimizer analyzes your code and applies statistics in order to derive the “best” execution plan. The other half of the battle is successfully applying that knowledge to the databases that you manage. The optimizer uses statistics as input to develop query execution plans, and so these statistics are the foundation of good plans. If the statistics supplied aren’t representative of your actual data, you can expect bad plans. However, if the statistics are representative of your data, then the optimizer will probably choose an optimal plan.
This document presents a comparison of a modified 64-bit binary comparator design and an existing 64-bit binary comparator design. The modified design implements the first stage using CMOS logic instead of pass transistor logic to improve speed. Simulation results show the modified design has a 0.47% reduction in delay for the A_LT_B output and a 1.23% reduction in delay for the A_EQU_B output compared to the existing design, while using more power and transistors. Therefore, the modified design provides better performance for high-speed applications.
High speed tree-based 64-bit cmos binary comparatoreSAT Journals
Abstract A high-speed tree-based 64-bit CMOS binary comparator is proposed in this brief. Comparison is most basic arithmetic operation that determines if one number is greater than, equal to, or less than the other number. Comparator is most fundamental component that performs comparison operation. This brief presents comparison of modified and existing 64-bit binary comparator designs concentrating on delay. Means some modifications are done in existing 64-bit binary comparator design to improve the speed of the circuit. Comparison between modified and existing 64-bit binary comparator designs is calculated by simulation that is performed at 90nm technology in Tanner EDA Tool. Index Terms: Binary comparator, digital arithmetic, high-speed
The document summarizes how SQL Plan Directives in Oracle 12c can help address issues caused by cardinality misestimation in the optimizer. It provides an example where the optimizer underestimates the number of rows returned by a query on a table due to not having statistics on correlated columns. In 12c, a SQL Plan Directive is automatically generated after the first execution to capture this misestimation. On subsequent queries, the directive can be used to provide more accurate cardinality estimates through automatic reoptimization or dynamic sampling.
Informix Warehouse Accelerator (IWA) features in version 12.1Keshav Murthy
The document discusses enhancements made to Informix Warehouse Accelerator (IWA) in version 12.10. Key points include:
- IWA now supports operations like creating, deploying, loading, enabling, and disabling data marts on secondary nodes in MACH11 and high availability environments, in addition to the primary/standard server node.
- New procedures like dropPartMart and loadPartMart allow refreshing partitions in a partitioned fact table within a data mart.
- Performance of SQL queries involving UNIONs, derived tables, and DISTINCT aggregates was improved.
- Additional OLAP functions and options like NULLS FIRST/LAST in ORDER BY were added for enhanced analytical querying.
This document discusses various Oracle SQL concepts including query optimization, execution plans, joins, indexes, and full table scans. It provides guidance on understanding how Oracle processes and executes SQL queries, the importance of statistics and selectivity, and techniques for writing efficient queries such as predicate pushing and query transformations. The goal is to help readers gain a conceptual understanding of Oracle's internals to formulate more efficient SQL.
The document discusses Exadata Smart Scan, which offloads SQL processing from the database layer to the storage cell layer. Smart Scan passes only the required data blocks filtered by predicates to the database server instead of all blocks. Testing shows that with Smart Scan, a count query takes 0.05 seconds versus 15.68 seconds without Smart Scan. Analysis of statistics with Smart Scan shows most blocks are filtered at the storage layer with only a small amount of data, about 0.18MB, returned to the database layer.
Introduce Brainf*ck, another Turing complete programming language. Then, try to implement the following from scratch: Interpreter, Compiler [x86_64 and ARM], and JIT Compiler.
The document discusses Test4pass, an expert in IT certification exams. It lists popular IT certifications from Microsoft, Cisco, IBM, and CompTIA and provides sample exam questions and answers related to Microsoft SQL Server 2008 database development.
This document provides an overview of PostgreSQL topics including:
- Installation and configuration best practices such as using package management and configuring logging
- Routine maintenance activities like vacuuming and backups
- Upgrades and the differences between major, minor, and bugfix versions
- Advanced SQL topics like window functions, common table expressions, and querying slow queries
Big Data Analytics with MariaDB ColumnStoreMariaDB plc
MariaDB ColumnStore is an open source columnar database storage engine that provides high performance analytics capabilities on large datasets using standard SQL. It uses a distributed architecture that stores data by column rather than by row to enable fast queries by only accessing the relevant columns. It can scale horizontally on commodity servers to support analytics workloads on datasets ranging from millions to trillions of rows.
The document provides an overview of execution plans in SQL Server and what aspects to examine. It discusses the key stages in the execution process including parsing, optimization, and execution. Specific operators like nested loops, hash matches, and parallelism are also covered. The document is intended to help beginners understand execution plans and what aspects provide useful information for troubleshooting query performance issues.
An overview presentation covering the use of Oracle's PX functionality including some tips and traps. Detailed white paper at http://oracledoug.com/px.html
The optimizer is the "brain" of the database, interpreting SQL queries and determining the fastest method of execution. In this talk by Bruce Momjian, Senior Database Architect at EnterpriseDB and co-founder of the PostgreSQL Global Development Group, uses the explain command to show how the optimizer interprets queries and determines optimal execution. The talk aimed at assisting developers and administrators in understanding how Postgres optimally executes their queries and what steps they can take to understand and perhaps improve its behavior.
Automated parameter optimization techniques like Caret can substantially improve the performance of defect prediction models over using default parameter settings. When applied to 18 datasets using 26 classification techniques, Caret optimized models improved average AUC performance by up to 40 percentage points for some techniques. Caret optimized models also tended to be more stable than default models, with the stability ratio being lower than 1 for 35% of techniques studied. Overall, automated parameter optimization can significantly enhance both the performance and stability of defect prediction models.
GSP 215 RANK Become Exceptional--gsp215rank.comclaric119
FOR MORE CLASSES VISIT
www.gsp215rank.com
Please check all Included Assignment Details below
GSP 215 Week 1 Homework Command Line in Windows and Linux
GSP 215 Week 2 iLab Binary Representation of Information
GSP 215 Week 2 Homework Representing and Manipulating Information
FOR MORE CLASSES VISIT
www.gsp215rank.com
Please check all Included Assignment Details below
GSP 215 Week 1 Homework Command Line in Windows and Linux
GSP 215 Week 2 iLab Binary Representation of Information
GSP 215 Week 2 Homework Representing and Manipulating Information
The document discusses how database optimizers can sometimes provide incorrect cardinality estimates that result in inefficient query plans. It provides four examples of cardinality errors caused by uneven data distributions. The key strategies for addressing cardinality problems are: 1) giving the optimizer more statistical information through histograms and SQL profiles, 2) overriding optimizer decisions with hints, and 3) changing the application design/data model. Providing more information to the optimizer usually improves plans without additional code changes.
This document contains a midterm exam for an Elements of Programming course. It consists of 4 sections - multiple choice, fill in the blank, short answer, and programming questions. The multiple choice and fill in the blank sections contain 10 questions each worth 1 mark each. The short answer section contains 3 questions worth a total of 40 marks. The programming question is worth 25 marks and requires the student to create a C++ program to simulate a vending machine. The exam is worth a total of 100 marks and students are instructed to answer all questions and show all working.
Learn SQL from basic queries to Advance queriesmanishkhaire30
Dive into the world of data analysis with our comprehensive guide on mastering SQL! This presentation offers a practical approach to learning SQL, focusing on real-world applications and hands-on practice. Whether you're a beginner or looking to sharpen your skills, this guide provides the tools you need to extract, analyze, and interpret data effectively.
Key Highlights:
Foundations of SQL: Understand the basics of SQL, including data retrieval, filtering, and aggregation.
Advanced Queries: Learn to craft complex queries to uncover deep insights from your data.
Data Trends and Patterns: Discover how to identify and interpret trends and patterns in your datasets.
Practical Examples: Follow step-by-step examples to apply SQL techniques in real-world scenarios.
Actionable Insights: Gain the skills to derive actionable insights that drive informed decision-making.
Join us on this journey to enhance your data analysis capabilities and unlock the full potential of SQL. Perfect for data enthusiasts, analysts, and anyone eager to harness the power of data!
#DataAnalysis #SQL #LearningSQL #DataInsights #DataScience #Analytics
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...sameer shah
"Join us for STATATHON, a dynamic 2-day event dedicated to exploring statistical knowledge and its real-world applications. From theory to practice, participants engage in intensive learning sessions, workshops, and challenges, fostering a deeper understanding of statistical methodologies and their significance in various fields."
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Kaxil Naik
Navigating today's data landscape isn't just about managing workflows; it's about strategically propelling your business forward. Apache Airflow has stood out as the benchmark in this arena, driving data orchestration forward since its early days. As we dive into the complexities of our current data-rich environment, where the sheer volume of information and its timely, accurate processing are crucial for AI and ML applications, the role of Airflow has never been more critical.
In my journey as the Senior Engineering Director and a pivotal member of Apache Airflow's Project Management Committee (PMC), I've witnessed Airflow transform data handling, making agility and insight the norm in an ever-evolving digital space. At Astronomer, our collaboration with leading AI & ML teams worldwide has not only tested but also proven Airflow's mettle in delivering data reliably and efficiently—data that now powers not just insights but core business functions.
This session is a deep dive into the essence of Airflow's success. We'll trace its evolution from a budding project to the backbone of data orchestration it is today, constantly adapting to meet the next wave of data challenges, including those brought on by Generative AI. It's this forward-thinking adaptability that keeps Airflow at the forefront of innovation, ready for whatever comes next.
The ever-growing demands of AI and ML applications have ushered in an era where sophisticated data management isn't a luxury—it's a necessity. Airflow's innate flexibility and scalability are what makes it indispensable in managing the intricate workflows of today, especially those involving Large Language Models (LLMs).
This talk isn't just a rundown of Airflow's features; it's about harnessing these capabilities to turn your data workflows into a strategic asset. Together, we'll explore how Airflow remains at the cutting edge of data orchestration, ensuring your organization is not just keeping pace but setting the pace in a data-driven future.
Session in https://budapestdata.hu/2024/04/kaxil-naik-astronomer-io/ | https://dataml24.sessionize.com/session/667627
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...Social Samosa
The Modern Marketing Reckoner (MMR) is a comprehensive resource packed with POVs from 60+ industry leaders on how AI is transforming the 4 key pillars of marketing – product, place, price and promotions.
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Aggregage
This webinar will explore cutting-edge, less familiar but powerful experimentation methodologies which address well-known limitations of standard A/B Testing. Designed for data and product leaders, this session aims to inspire the embrace of innovative approaches and provide insights into the frontiers of experimentation!
Analysis insight about a Flyball dog competition team's performanceroli9797
Insight of my analysis about a Flyball dog competition team's last year performance. Find more: https://github.com/rolandnagy-ds/flyball_race_analysis/tree/main
Build applications with generative AI on Google CloudMárton Kodok
We will explore Vertex AI - Model Garden powered experiences, we are going to learn more about the integration of these generative AI APIs. We are going to see in action what the Gemini family of generative models are for developers to build and deploy AI-driven applications. Vertex AI includes a suite of foundation models, these are referred to as the PaLM and Gemini family of generative ai models, and they come in different versions. We are going to cover how to use via API to: - execute prompts in text and chat - cover multimodal use cases with image prompts. - finetune and distill to improve knowledge domains - run function calls with foundation models to optimize them for specific tasks. At the end of the session, developers will understand how to innovate with generative AI and develop apps using the generative ai industry trends.
Predictably Improve Your B2B Tech Company's Performance by Leveraging DataKiwi Creative
Harness the power of AI-backed reports, benchmarking and data analysis to predict trends and detect anomalies in your marketing efforts.
Peter Caputa, CEO at Databox, reveals how you can discover the strategies and tools to increase your growth rate (and margins!).
From metrics to track to data habits to pick up, enhance your reporting for powerful insights to improve your B2B tech company's marketing.
- - -
This is the webinar recording from the June 2024 HubSpot User Group (HUG) for B2B Technology USA.
Watch the video recording at https://youtu.be/5vjwGfPN9lw
Sign up for future HUG events at https://events.hubspot.com/b2b-technology-usa/
3. 問題のクエリ
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
5. 対象データと結果
対象データ
select * from ProductTests;
batch_nbr | prod_code | prod_quality
-----------+-----------+--------------
1 | A | 80.0000
2 | A | 70.0000
3 | A | 80.0000
4 | B | 60.0000
5 | B | 90.0000
6 | C | 80.0000
7 | D | 80.0000
8 | A | 50.0000
9 | C | 70.0000
(9 rows)
件のSQLの実行結果
prod_code | start_batch_nbr | end_batch_nbr | avg_prod_quality
-----------+-----------------+---------------+---------------------
A | 1 | 3 | 76.6666666666666667
B | 4 | 5 | 75.0000000000000000
C | 6 | 6 | 80.0000000000000000
D | 7 | 7 | 80.0000000000000000
A | 8 | 8 | 50.0000000000000000
C | 9 | 9 | 70.0000000000000000
(6 rows)
6. クエリ解説1※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
1 | A | 80.0000 | 8 | A | 50.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 8 | A | 50.0000
3 | A | 80.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 8 | A | 50.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
6 | C | 80.0000 | 9 | C | 70.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(17 rows)
7. ※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
クエリ解説1-1
元データ
select * from ProductTests;
batch_nbr | prod_code | prod_quality
-----------+-----------+--------------
1 | A | 80.0000
2 | A | 70.0000
3 | A | 80.0000
4 | B | 60.0000
5 | B | 90.0000
6 | C | 80.0000
7 | D | 80.0000
8 | A | 50.0000
9 | C | 70.0000
prod_codeが同じでbatch_nbrが大きいものと自己結合します
Aに限って考えると、Aのバッチ番号は{1,2,3,8}なので
{11,12,13,18, 22,23,28, 33,38, 88}の10通りのペアができます
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
1 | A | 80.0000 | 8 | A | 50.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 8 | A | 50.0000
3 | A | 80.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 8 | A | 50.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
6 | C | 80.0000 | 9 | C | 70.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(17 rows)
SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
8. クエリ解説2※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 3 | A | 80.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(13 rows)
9. ※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
クエリ解説2-1
青色の行が消えます
batch_nbr | prod_code | prod_quality | batch_nbr | prod_quality
-----------+-----------+--------------+-----------+--------------
1 | A | 80.0000 | 1 | 80.0000
1 | A | 80.0000 | 2 | 70.0000
1 | A | 80.0000 | 3 | 80.0000
1 | A | 80.0000 | 8 | 50.0000
2 | A | 70.0000 | 2 | 70.0000
2 | A | 70.0000 | 3 | 80.0000
2 | A | 70.0000 | 8 | 50.0000
3 | A | 80.0000 | 3 | 80.0000
3 | A | 80.0000 | 8 | 50.0000
4 | B | 60.0000 | 4 | 60.0000
4 | B | 60.0000 | 5 | 90.0000
5 | B | 90.0000 | 5 | 90.0000
6 | C | 80.0000 | 6 | 80.0000
6 | C | 80.0000 | 9 | 70.0000
7 | D | 80.0000 | 7 | 80.0000
8 | A | 50.0000 | 8 | 50.0000
9 | C | 70.0000 | 9 | 70.0000
(17 rows)
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 3 | A | 80.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(13 rows)
またまたAに限ったケースで考えると…
10. ※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
クエリ解説2-2
青色の行が消えます
batch_nbr | prod_code | prod_quality | batch_nbr | prod_quality
-----------+-----------+--------------+-----------+--------------
1 | A | 80.0000 | 1 | 80.0000
1 | A | 80.0000 | 2 | 70.0000
1 | A | 80.0000 | 3 | 80.0000
1 | A | 80.0000 | 8 | 50.0000
2 | A | 70.0000 | 2 | 70.0000
2 | A | 70.0000 | 3 | 80.0000
2 | A | 70.0000 | 8 | 50.0000
3 | A | 80.0000 | 3 | 80.0000
3 | A | 80.0000 | 8 | 50.0000
4 | B | 60.0000 | 4 | 60.0000
4 | B | 60.0000 | 5 | 90.0000
5 | B | 90.0000 | 5 | 90.0000
6 | C | 80.0000 | 6 | 80.0000
6 | C | 80.0000 | 9 | 70.0000
7 | D | 80.0000 | 7 | 80.0000
8 | A | 50.0000 | 8 | 50.0000
9 | C | 70.0000 | 9 | 70.0000
(17 rows)
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 3 | A | 80.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(13 rows)
ALL述語の条件は若干わかりにくいが、
自己結合したテーブル
B1とB2において、
B1.batch_nbr B2.batch_nbr
間のprod_codeの値が
全て一致する行を残すための相関サブクエリ
1 3や2 3間は全てAなので残る
2 8間では、4にB、6にCが混じるので
ALL述語が成り立たない。=消える
11. クエリ解説3※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
prod_code | batch_nbr | end_batch_nbr
-----------+-----------+---------------
A | 1 | 3
A | 2 | 3
A | 3 | 3
B | 4 | 5
B | 5 | 5
C | 6 | 6
D | 7 | 7
A | 8 | 8
C | 9 | 9
(9 rows)
12. クエリ解説3-1※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
prod_code | batch_nbr | end_batch_nbr
-----------+-----------+---------------
A | 1 | 3
A | 2 | 3
A | 3 | 3
B | 4 | 5
B | 5 | 5
C | 6 | 6
D | 7 | 7
A | 8 | 8
C | 9 | 9
(9 rows)
対象データ
select * from ProductTests;
batch_nbr | prod_code | prod_quality
-----------+-----------+--------------
1 | A | 80.0000
2 | A | 70.0000
3 | A | 80.0000
4 | B | 60.0000
5 | B | 90.0000
6 | C | 80.0000
7 | D | 80.0000
8 | A | 50.0000
9 | C | 70.0000
(9 rows)
連続している製品グループ群の最後のbatch_nbrを
end_batch_nbrに格納している
13. クエリ解説4※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※赤字の部分のまま実行できないのでselect * from ()で括ってサブクエリとして実行しています
prod_code | batch_nbr | end_batch_nbr | prod_quality
-----------+-----------+---------------+--------------
A | 1 | 3 | 80.0000
A | 2 | 3 | 70.0000
A | 3 | 3 | 80.0000
B | 4 | 5 | 60.0000
B | 5 | 5 | 90.0000
C | 6 | 6 | 80.0000
D | 7 | 7 | 80.0000
A | 8 | 8 | 50.0000
C | 9 | 9 | 70.0000
(9 rows)
内部結合でprod_qualityを付け足しただけ。
14. クエリ解説5※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
prod_code | start_batch_nbr | end_batch_nbr | avg_prod_quality
-----------+-----------------+---------------+---------------------
A | 1 | 3 | 76.6666666666666667
B | 4 | 5 | 75.0000000000000000
C | 6 | 6 | 80.0000000000000000
D | 7 | 7 | 80.0000000000000000
A | 8 | 8 | 50.0000000000000000
C | 9 | 9 | 70.0000000000000000
(6 rows)
赤字の列でgroup by。
・最小値(同じ製品のシーケンシャルなグループの開始位置)
・平均値
を集計関数で計算して表示
15. 完成
対象データ
select * from ProductTests;
batch_nbr | prod_code | prod_quality
-----------+-----------+--------------
1 | A | 80.0000
2 | A | 70.0000
3 | A | 80.0000
4 | B | 60.0000
5 | B | 90.0000
6 | C | 80.0000
7 | D | 80.0000
8 | A | 50.0000
9 | C | 70.0000
(9 rows)
prod_code | start_batch_nbr | end_batch_nbr | avg_prod_quality
-----------+-----------------+---------------+---------------------
A | 1 | 3 | 76.6666666666666667
B | 4 | 5 | 75.0000000000000000
C | 6 | 6 | 80.0000000000000000
D | 7 | 7 | 80.0000000000000000
A | 8 | 8 | 50.0000000000000000
C | 9 | 9 | 70.0000000000000000
(6 rows)
16. おさらい1※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
1 | A | 80.0000 | 8 | A | 50.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 8 | A | 50.0000
3 | A | 80.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 8 | A | 50.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
6 | C | 80.0000 | 9 | C | 70.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(17 rows)
17. おさらい2※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※注意1 SELECT句の列指定は*としました。
※注意2 わかりやすさのためOrder byを加えています(行順意外に結果はありません)
batch_nbr | prod_code | prod_quality | batch_nbr | prod_code | prod_quality
-----------+-----------+--------------+-----------+-----------+--------------
1 | A | 80.0000 | 1 | A | 80.0000
1 | A | 80.0000 | 2 | A | 70.0000
1 | A | 80.0000 | 3 | A | 80.0000
2 | A | 70.0000 | 2 | A | 70.0000
2 | A | 70.0000 | 3 | A | 80.0000
3 | A | 80.0000 | 3 | A | 80.0000
4 | B | 60.0000 | 4 | B | 60.0000
4 | B | 60.0000 | 5 | B | 90.0000
5 | B | 90.0000 | 5 | B | 90.0000
6 | C | 80.0000 | 6 | C | 80.0000
7 | D | 80.0000 | 7 | D | 80.0000
8 | A | 50.0000 | 8 | A | 50.0000
9 | C | 70.0000 | 9 | C | 70.0000
(13 rows)
18. おさらい3※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
prod_code | batch_nbr | end_batch_nbr
-----------+-----------+---------------
A | 1 | 3
A | 2 | 3
A | 3 | 3
B | 4 | 5
B | 5 | 5
C | 6 | 6
D | 7 | 7
A | 8 | 8
C | 9 | 9
(9 rows)
19. おさらい4※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
※赤字の部分のまま実行できないのでselect * from ()で括ってサブクエリとして実行しています
prod_code | batch_nbr | end_batch_nbr | prod_quality
-----------+-----------+---------------+--------------
A | 1 | 3 | 80.0000
A | 2 | 3 | 70.0000
A | 3 | 3 | 80.0000
B | 4 | 5 | 60.0000
B | 5 | 5 | 90.0000
C | 6 | 6 | 80.0000
D | 7 | 7 | 80.0000
A | 8 | 8 | 50.0000
C | 9 | 9 | 70.0000
(9 rows)
内部結合でprod_qualityを付け足しただけ。
20. おさらい5※実行SQLは赤字で示します
SELECT X.prod_code, MIN(X.batch_nbr) AS start_batch_nbr, end_batch_nbr,
AVG(B4.prod_quality) AS avg_prod_quality
FROM (SELECT B1.prod_code, B1.batch_nbr,
MAX(B2.batch_nbr) AS end_batch_nbr
FROM ProductTests AS B1, ProductTests AS B2
WHERE B1.batch_nbr <= B2.batch_nbr
AND B1.prod_code = B2.prod_code
AND B1.prod_code
= ALL (SELECT prod_code
FROM ProductTests AS B3
WHERE B3.batch_nbr BETWEEN B1.batch_nbr
AND B2.batch_nbr)
GROUP BY B1.prod_code, B1.batch_nbr) AS X
INNER JOIN
ProductTests AS B4
ON B4.prod_code = X.prod_code
AND B4.batch_nbr = X.batch_nbr
GROUP BY X.prod_code, X.end_batch_nbr;
prod_code | start_batch_nbr | end_batch_nbr | avg_prod_quality
-----------+-----------------+---------------+---------------------
A | 1 | 3 | 76.6666666666666667
B | 4 | 5 | 75.0000000000000000
C | 6 | 6 | 80.0000000000000000
D | 7 | 7 | 80.0000000000000000
A | 8 | 8 | 50.0000000000000000
C | 9 | 9 | 70.0000000000000000
(6 rows)
赤字の列でgroup by。
・最小値(同じ製品のシーケンシャルなグループの開始位置)
・平均値
を集計関数で計算して表示