Home Database Mysql Tutorial SQL 巩固练习(用到了前几天几个知识点)

SQL 巩固练习(用到了前几天几个知识点)

Jun 07, 2016 pm 05:44 PM
several Knowledge points practise

SQL 巩固练习用到了前几天几个知识点 在查看SQL Server 2005的帮助文档中的cross apply 运算符时发现了一个个人感觉用到的知识点儿比较多,比较经典的例子。在此写下来,也是为了巩固一下前几天的知识点。 先建表一员工表(Employees): CREATE TABLE Emplo

SQL 巩固练习——用到了前几天几个知识点

  在查看SQL Server 2005的帮助文档中的cross apply 运算符时发现了一个个人感觉用到的知识点儿比较多,免备案空间,比较经典的例子。在此写下来,香港空间,也是为了巩固一下前几天的知识点。

先建表一员工表(Employees):

CREATE TABLE Employees ( empid , mgrid int NULL, empname varchar(25) NOT NULL, salary , CONSTRAINT PK_Employees PRIMARY KEY(empid), )

向Employees表中插入数据:

Employees , $10000.00) , $5000.00) , $5000.00) , $5000.00) , $2500.00) , $2500.00) , $2500.00) , $2500.00) , $2500.00) , $2500.00) , $2000.00) , $2000.00) , $2000.00) , $1500.00)

查询向Employees表插入的全部数据SQL语句:

Employees

结果如图:

再建表二部门表(Departments):

CREATE TABLE Departments ( deptid , deptname VARCHAR(25) NOT NULL, deptmgrid Employees )

Departments表插入数据:

, 2) , 7) , 8) , 9) , 4) , NULL)

查询向Departments表插入的全部数据SQL语句:

Departments

结果如图:

下面的表值函数使用雇员 ID 作为参数,并返回该雇员及他/她的所有下属(用到了前面所学的CTE公共表表达式 with...as... 的递归):

) ( empid , empname VARCHAR(25) NOT NULL, mgrid INT NULL, lvl ) Employees_Subtree(empid, empname, mgrid, lvl) AS ( empid, empname, mgrid, 0 FROM employees e.empid, e.empname, e.mgrid, es.lvlemployees AS e JOIN employees_subtree AS es ON e.mgrid = es.empid ) Employees_Subtree

返回每个部门经理的所有级别的全部下属,使用下面的SQL语句(用到了apply的cross apply):

Departments AS D CROSS APPLY fn_getsubtree(D.deptmgrid) AS ST

结果如图:

,虚拟主机
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Python cheat sheet collection, what knowledge points have you mastered? Python cheat sheet collection, what knowledge points have you mastered? Apr 26, 2023 pm 10:49 PM

Python is currently the most popular programming language. I believe that a large number of novice friends will join the ranks of learning every day. However, no matter how easy a language is to learn, there are still many basic concepts and basic knowledge. For a novice, it is still difficult to master so many in one time. Today, we have collected many Python-related knowledge cheat sheets, which can be said to be all-inclusive. In the future, mom will no longer have to worry about everyone not being able to remember any knowledge points! Python basics Pythonbasics This cheat sheet contains all the basic knowledge of Python, from variable data types to list strings, from environment installation to the use of commonly used libraries, it can be said to be comprehensive. Beginner'sPytho

How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide How to practice typing with Kingsoft Typing Guide - How to practice typing with Kingsoft Typing Guide Mar 18, 2024 pm 04:25 PM

Nowadays, many friends like to use Kingsoft Typing Assistant, but the typing speed seriously affects work efficiency, so I teach you to practice typing speed. So how to use Kingsoft Typing Assistant to practice typing? Today, the editor will give you a tutorial on how to practice typing numbers with Kingsoft Typing Assistant. The following is described, I hope it will be helpful to everyone. First, open the Kingsoft typing software, then click the (Getting Started) button with your mouse, then click the (Number Keys) button in a new window, then click the (Start from Scratch) button below to practice, or click the (Test Mode) button. , just enter numbers for practice. In addition, Kingsoft Typing Assistant has other functions that can help you practice typing better. 1. Select practice mode: On the software interface, you can see that there are different practice modes, such as "New

How to practice Wubi typing for beginners - Wubi input method typing practice How to practice Wubi typing for beginners - Wubi input method typing practice Mar 18, 2024 pm 06:30 PM

Wubi typing, also known as Wubi input method, is an efficient Chinese character input method. For beginners, mastering Wubi typing requires a certain amount of time and patience. Below, the editor has compiled the learning methods for Wubi typing beginners. Let’s take a look! 1. Understand the principles of Wubi font Wubi font is a type of font based on Input method for strokes and radicals. Each Chinese character can be composed of different strokes and radicals. Therefore, the key to learning Wubi font is to understand the combination rules of strokes and root characters. In the five-stroke font, there are five basic strokes: horizontal, vertical, left, right, and fold. These basic strokes can be combined into different radicals, which in turn can be combined into complete Chinese characters. 2. Learn the radicals and key positions. In Wubi font, each letter key corresponds to one or more radicals. therefore

Revealing the secret of HTML caching mechanism: essential knowledge points Revealing the secret of HTML caching mechanism: essential knowledge points Jan 23, 2024 am 08:51 AM

The secret of HTML caching mechanism: essential knowledge points, specific code examples are required In web development, performance has always been an important consideration. The HTML caching mechanism is one of the keys to improving the performance of web pages. This article will reveal the principles and practical skills of the HTML caching mechanism, and provide specific code examples. 1. Principle of HTML caching mechanism During the process of accessing a Web page, the browser requests the server to obtain the HTML page through the HTTP protocol. HTML caching mechanism is to cache HTML pages in the browser

Regular expression exercises in Java Regular expression exercises in Java Jun 16, 2023 pm 02:36 PM

In Java, regular expressions are one of the most commonly used technologies and can be used in almost any text processing scenario, such as text search, extraction, analysis, replacement, etc. Its powerful matching capabilities can greatly improve development efficiency, while making the code more concise and easier to maintain. The following are some regular expression exercises in Java to help you master the application of regular expressions. Regular expression for matching Chinese characters: [u4e00-u9fa5] Explanation: The Unicode code value range of Chinese characters is from 4e00 to 9f

Detailed explanation of MySQL data types: What you need to know Detailed explanation of MySQL data types: What you need to know Jun 15, 2023 am 08:56 AM

MySQL is one of the most popular relational database management systems in the world and is widely used because of its reliability, high security, high scalability and relatively low cost. MySQL data types define the storage methods of various data types and are an important part of MySQL. This article will explain in detail the data types of MySQL and some knowledge points that need to be paid attention to in practical applications. 1. MySQL data type classification MySQL data types can be divided into the following categories: Integer types: including TINYINT,

Oracle data types revealed: knowledge points you must know Oracle data types revealed: knowledge points you must know Mar 07, 2024 pm 05:18 PM

Oracle data types revealed: knowledge points you must understand and specific code examples required. Oracle, as one of the world's leading database management systems, plays an important role in data storage and processing. In Oracle, data type is a very important concept, which defines the storage format, range and operation method of data in the database. This article will reveal various knowledge points of Oracle data types and demonstrate their usage and characteristics through specific code examples. 1. Common data types character data types

I can't pass the basic PHP written test, how can I improve? I can't pass the basic PHP written test, how can I improve? Mar 01, 2024 pm 12:12 PM

PHP is a language widely used in the field of web development, and mastering its basic knowledge is crucial for those engaged in PHP development. When facing a situation where you fail to pass the basic PHP written test, it is crucial to improve your PHP capabilities. The following will introduce how to improve the basic knowledge of PHP from several aspects. First of all, it is recommended to systematically learn the PHP language from the basics, including basic knowledge such as syntax, variables, constants, operators, arrays, functions, etc. You can learn P systematically by reading relevant books, watching online tutorials or attending training courses

See all articles