SQL procedure User's Guide

1. Ordering the SELECT Statement:

  1.select

  2. From

  3. Where

  4. Group by

  5. Having

  6. Order by

select Continent, sum(Population)
from sql.countries
group by Continent
having Continent in (‘Asia‘, ‘Europe‘)
order by Continent;

2. The OUTOBS=option limits the number of rows in the output. OUTOBS= is similar   
  to the OBS=data set option

proc sql outobs=12;
title ‘U.S. Cities with Their States and Coordinates‘;
select *
from sql.uscitycoords;

3. The keyword Distinct can eliminate the duplicate rows from the results

PROC sql;
    title ‘Continents of the United States‘;
    select distinct Continent
        from sql.unitedstates;
quit;

4. Determing the structure of a Table:

  The DESCRIBE TABLE statement: obtain a list of all of the columns in a table and

  their attributes.

proc sql;
    describe table sql.unitedstates;
quit;

Creating New Columns:
  Adding Text to Output:

proc sql outobs=12;
title ‘U.S. Postal Codes‘;
select ‘Postal code for‘, Name, ‘is‘, Code
from sql.postalcodes;
quit
proc sql outobs=12;
title ‘U.S. Postal Codes‘;
select ‘Postal code for‘, Name label=‘#‘, ‘is‘, Code label=‘#‘
from sql.postalcodes;
quit

Referring to a Calculated Column by Alias (keyword: Calculated)

proc sql outobs=12;
title ‘Range of High and Low Temperatures in Celsius‘;
select City, (AvgHigh - 32) * 5/9 as HighC format=5.1,
    (AvgLow - 32) * 5/9 as LowC format=5.1,
    (calculated HighC - calculated LowC)
    as Range format=4.1
from sql.worldtemps;

Assigning Values Conditionally:

  1. Using a simple Case expression

  2. Using the case-operand from

proc sql outobs=12;
title ‘Climate Zones of World Cities‘;
    select City, Country, Latitude,
    case
        when Latitude gt 67 then ‘North Frigid‘
        when 67 ge Latitude ge 23 then ‘North Temperate‘
        when 23 gt Latitude gt -23 then ‘Torrid‘
        when -23 ge Latitude ge -67 then ‘South Temperate‘
        else ‘South Frigid‘
    end as ClimateZone
from sql.worldcitycoords
order by City;    

proc sql outobs=12;
title ‘Assigning Regions to Continents‘;
    select Name, Continent,
    case Continent
        when ‘North America‘ then ‘Continental U.S.‘
        when ‘Oceania‘ then ‘Pacific Islands‘
        else ‘None‘
    end as Region
from sql.unitedstates;

SQL procedure User's Guide

时间: 2024-08-05 03:06:00

SQL procedure User's Guide的相关文章

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 val

Apache Spark 2.2.0 中文文档 - Spark SQL, DataFrames and Datasets Guide | ApacheCN

Spark SQL, DataFrames and Datasets Guide Overview SQL Datasets and DataFrames 开始入门 起始点: SparkSession 创建 DataFrames 无类型的Dataset操作 (aka DataFrame 操作) Running SQL Queries Programmatically 全局临时视图 创建Datasets RDD的互操作性 使用反射推断Schema 以编程的方式指定Schema Aggregatio

SQL Procedure Operations

This Class is used to handle SQL procedures, including Verify SP exist or not, Create SP into DB and Execute SP via C#. using System; using System.Data.SqlClient; using System.Collections.Generic; using System.Linq; using System.Text; using System.Da

Calling a PL/SQL procedure in ODI

新建procedure 新建一个测试表格EMP: CREATE TABLE EMP ( EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2) ); 新建一个procedure,往EMP表插入一条记录 CREATE OR R

【分享】近4000份数学学习资源免费分享给大家

一直以来喜欢收集数学类的教程资源,于是费了好大劲从万千合集站上扒拉了下来,总结归类了一下,一共有将近4000本电子书.经测试,均可免费下载,可能会弹出小广告,可不必理会之.[仅供学术学习和交流,请无用于商业用途.]另外,如有可能,还请尽量支持正版纸质书.   数学史(54)     数学史.rar 55.6 MB   数学的起源与发展.rar 4.3 MB   费马大定理—一个困惑了世间智者358年的谜.pdf 9.5 MB   通俗数学名著译丛14-无穷之旅:关于无穷大的文化史.pdf 14.

P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May 2016 Contents About This Guide...................................................................................... 11 Shared Topics in This Guide .

P6 EPPM Manual Installation Guide (Oracle Database)

Contents Oracle Database Manual Configuration Overview ,,★★5 Oracle Database Installation ,,★★6 Creating the Database Structure for Oracle and Loading Application Data ,,★★7 Creating the P6 EPPM Database Structure for Oracle ,,★★7 Copying the Script

P6 EPPM Installation and Configuration Guide 16 R1 April 2016

P6 EPPM Installation and Configuration Guide 16 R1         April 2016 Contents About Installing and Configuring P6 EPPM ........................................................ 6 Prerequisites for P6 EPPM Configuration ...............................

Migrating Oracle on UNIX to SQL Server on Windows

Appendices Published: April 27, 2005 On This Page Appendix A: SQL Server for Oracle Professionals Appendix B: Getting the Best Out of SQL Server 2000 and Windows Appendix C: Baselining Appendix D: Installing Common Drivers and Applications Installing