Conditional Mass Update of Data in Google Sheets Using SQL

Categories:

One of the tasks that cannot be solved using standard Google Sheets tools but can be handled with an SQL query is mass updating data with conditions. For example:

Task: Increase the Annual Salary by 10% for all employees working in the “IT” department who have more than 5 years of tenure.

SQL query for this task:

UPDATE "Employees!A1:E5?headers=1"
SET
  Salary = Salary * 1.10
WHERE
  Department = 'IT'
  AND strftime ('%Y', 'now') - strftime ('%Y', "Hire Date") > 5;

Why this is challenging to implement using standard Google Sheets tools:

  1. Mass updates: In Google Sheets, you would need to manually calculate tenure, filter data, add helper columns, and then recalculate salaries.
  2. Conditional updates: Formulas in Google Sheets work on individual cells or ranges but cannot apply mass updates based on conditions (e.g., tenure and department).
  3. Automation: Applying such changes requires manual copying and pasting of data into the original table, increasing the risk of errors.

SQL enables you to execute all these actions in a single query, ensuring precision and automation.

Using SQL in Google Sheets

With the SheetQuery add-on, you can run SQL queries directly in Google Sheets:

  1. Install SheetQuery from the Google Workspace Marketplace.
  2. Get a sample dataset
  3. Run the query above.