zoukankan      html  css  js  c++  java
  • SQL Procedure User's Guide (Multiple Table)

    Selecting Data from More than One Table by Using Joins

      Inner Joins: An Inner join returns only the subset of rows from the first table that matches rows from the second table You can specifies the columns that you want to be compared for matching values in a WHERE clause.

      Inner Joins... On: The Inner Join keywords can be used to join tables. The ON clause replaces the WHERE clause for specifying columns to join.

      The Effects of Null Values on Joins: PROC SQL treats null as missing values and as matches for joins.Any null will match with any other null of the same type in a join

      

    Showing Relationships within a Single Table Using Self-Joins:

    proc sql;
    title "Cities' High Temps = Cities' Low Temps";
    select High.City format $12., High.Country format $12.,
             High.AvgHigh, ' | ',
             Low.City format $12., Low.Country format $12.,
             Low.AvgLow
        from sql.worldtemps High, sql.worldtemps Low
        where High.AvgHigh = Low.AvgLow and
                  High.city ne Low.city and
                  High.country ne Low.country;

      Outer Joins: The Outer Joins are inner joins that are augmented with rows from one table that do not match any row from the other table in the join.The resulting output includes rows that match and rows that do not match from the join's source tables.Nonmatching rows have null values in the columns from the unmatched table.

      LEFT JOIN...ON...

      

      RIGHT JOIN...ON...

      FULL JOIN...ON...

     

      Specialty Joins: Three types of joins--> cross joins,union joins, and natural joins

        1. cross joins : Including All combinations of Rows with the cross join.

    proc sql;
    title 'Table One and Table Two';
    select *
    from one cross join two;

      2.Unoin Join: A unoin join combines two tables without attempting to match row. all columns and rows from both tables are include

      3.Natural Join : A natural join automatically selects columns from each table to use in determing matching rows. With a natural join,PROC SQL identifies columns in each table that have the same name and type,rows in which the values of these columns are equal are returned as matching rows.The ON clause is implied

    Using Subqueries to Select Data

       1. Single-Value Subqueries:

    proc sql;
    title 'U.S. States with Population Greater than Belgium';
    select Name 'State' , population format=comma10.
        from sql.unitedstates
            where population gt
                (select population from sql.countries
                         where name = "Belgium");        

      2.Multiple-Value Subqueries:

        It is used in a WHRER or HAVING expression that contains IN or a comparision operator that is modified by ANY or ALL.

    libname sql 'SAS-library';
    proc sql outobs=5;
    title 'Populations of Major Oil Producing Countries';
    select name 'Country', Population format=comma15.
        from sql.countries
            where Name in
                (select Country from sql.oilprod);    

      3. Correlated Subqueries:
        A correlated subquery requires a value or values to be passed to it by the outer query, After the subquery runs, it passes the results back to the outer query

    proc sql;
    title 'Oil Reserves of Countries in Africa';
    select * from sql.oilrsrvs o
        where 'Africa' =
                    (select Continent from sql.countries c
                            where c.Name = o.Country);

      4. Testing for the Existence of a Group of Values:

    proc sql;
    title 'Oil Reserves of Countries in Africa';
    select * from sql.oilrsrvs o
        where exists
            (select Continent from sql.countries c
                        where o.Country = c.Name and
                        Continent = 'Africa');

    Combining Queries with Set Operators:

      1. UNION : produces all unique rows from both queries.

      2. UNION ALL

      

      3 .EXCEPT:  produces rows that are part of the first query only

      4. INTERSECT: proudces rows that are common to both query results

      5. OUTER UNION: concatenates the query results.

      6.UNION Corr.

      

      

      

  • 相关阅读:
    ONNX 开始
    Linux 性能相关工具
    Prometheus + Grafana 快速上手
    RTSP 流相关工具介绍
    TensorFlow Serving
    TensorFlow 的 JupyterLab 环境
    【排序算法动画解】排序介绍及冒泡排序
    上课老师提问我什么是二叉查找树,我把这些动图拿了出来,动图图解及代码实现。
    如何找东西?查找算法之顺序查找和二分查找详解
    【数据结构和算法:简单方法】谈一谈优先队列的实现
  • 原文地址:https://www.cnblogs.com/easy-wang/p/6432002.html
Copyright © 2011-2022 走看看