ICON

Help - SQL BETWEEN operators

Help Center Data SQL BETWEEN operators

BETWEEN operators

3 MIN EXPERT DATA, SQL QUERIES, SQL RANGE


This functionality is only available in Spotzi Studio.

The BETWEEN operator is used to create an SQL query that filters rows within a specific range. The BETWEEN operator works with numbers, text (strings) and dates. A WHERE clause with a BETWEEN operator looks like this:

SELECT * FROM {name of dataset}
WHERE {column} BETWEEN {value1} AND {value2};

In the example below we have a dataset with 2-digit postal codes from the US. Each postal code area has one sales manager, but a sales manager can be responsible for several postal code areas.

BETWEEN Query

Let’s say we only want to show the areas with area IDs between 25032 and 30100. In that case the WHERE query will look like this.

SELECT * FROM usa_salesmanagers_2_digit_areas
WHERE area_id_number BETWEEN 25032 AND 30100;

BETWEEN Query

Now let’s say we only want to show the areas where the sales manager name is between Adam and Devlin, i.e. where the name of the sales manager starts with a letter between A and D. In that case the WHERE query will look like this.

SELECT * FROM usa_salesmanagers_2_digit_areas
WHERE area_id_number BETWEEN 'Adam' AND 'Devlin';

BETWEEN Query

Order your BETWEEN query


If you only want to have a look at the data without focusing on the geographic components, it might come in handy to order the data in the output table of the BETWEEN query . To do this, press the small arrow next to the table header of the column that contains the values you used as filters in your BETWEEN query. A small drop down menu will appear with the options to arrange the data in ascending or descending order.

BETWEEN Query

Related blog posts

Interested in our solutions? Please contact our sales team.

Whether you are new to data analytics or already an expert. We offer solutions for everyone. You don’t need to be a data expert to work with Spotzi Location. For more tailor made solutions we offer Spotzi Studio. With this plan you cannot only manage the data yourself but also connect to our API and manage users for the dashboards you create. Or work with our Market Ready Dashboards and drive on autopilot.