# Accessing Members of a Structured Data Set by Sequence Numbers

## 1. Access one member by one sequence number each time

We can get one record from a data table according to one sequence number.

【Example 1】 Get the information of the first and the last transaction days in Shanghai Stock Exchange in the year of 2019. Below is part of the source data:

【SPL script】

A3’s result:

At certain occasions we need to get the sequence number of member in the specified position, from back to front sometimes. To get the sequence number of the second to last transaction date from the above records ordered by date, for instance, we can use the parameter -2 to do this.

【Example 2】 Based on the EMPLOYEE table, calculate the average salary for the states of [California, Texas, New York, Florida] and for other states as a whole, which are classified as “Other”. Below is part of the source data:

【SPL script】

A5’s result:

## 2. Access members by multiple sequence numbers each time

At times we need to get a number of records according to multiple sequence numbers. For example, we can use a set of sequence numbers [4,5,6] to access records of the second quarter from a certain year’s sales table ordered by months; or we can access the weekend duty records using a set of sequence numbers [1,7] from a weekly on-duty table.

【Example 3】 The following is part of a table that records daily attendant information:

We want to group the table every 7 records and then convert it to the following format:

【SPL script】

A4’s result:

We can also access members from back to front.

【Example 5】 Calculate the growth rate of each closing price in SSE’s last 10 trading dates of the year 2019 compared with the previous closing price. Below is part of the source data:

【SPL script】

A4’s result:

## 3. Access members by the specified span

Another scenario is to access a series of members beginning from the specific sequence number according to a specified span. To get one sample from every 10 records in a data table, for instance, we can begin from the first record and get one within every ten. Another instance is to find all multiples of 3 from the natural numbers from 1 to 100. To do that, we can begin from the third number and get one every 3 numbers.

【Example 6】 Find the prime numbers within 100.

【SPL script】

A4’s result:

Find more examples in SPL CookBook.