Custom functions used in Google Sheets for ease of use and improved functionality.
=gsSQL( SelectSqlStatement, [TableDefinitions], [ColumnOutputFlag], [BindVariableData])
"SELECT transaction_date from master_transactions"
=gsSQL("select * from authors")
=gsSQL
(
"SELECT
books.id, books.title, books.type, authors.last_name, translators.last_name
FROM books
LEFT JOIN authors ON books.author_id = authors.id
LEFT JOIN translators ON books.translator_id = translators.id
ORDER BY books.id"
)
=gsSQL("SELECT
books.id, books.title, books.type, authors.last_name, translators.last_name
FROM books
LEFT JOIN authors ON books.author_id = authors.id
LEFT JOIN translators ON books.translator_id = translators.id
ORDER BY books.id", "books", Books!A1:F, "authors", Authors!A1:C, "translators", Translators!A1:C)
=gsSQL("SELECT
books.id, books.title, authors.first_name, authors.last_name
FROM
books
INNER JOIN
authors ON books.author_id = authors.id
ORDER BY
books.id",
"books", Books!A1:F, "authors", Authors!A1:C, true)
=gsSQL
(
"SELECT
booksales.A as 'Invoice', booksales.B as 'Book ID', CUST.A, CUST.B
FROM booksales
LEFT JOIN customers as CUST on booksales.C = customers.A ",
{{"CUSTOMERS","CUSTOMERS!A2:F",60, false}; {"BOOKSALES","BOOKSALES!A2:F",60, false}}, true
)
=gsSQL
(
"select
booksales.invoice as 'Invoice', booksales.quantity as 'Quantity', booksales.price as 'Price', booksales.quantity * booksales.price as 'Sales', booksales.date, books.title, customers.name, authors.first_name + ' ' + authors.last_name as 'Author', translators.first_name + ' ' + translators.last_name as 'Translator', editors.first_name + ' ' + editors.last_name as 'Editor'
from booksales left join books on booksales.book_id = books.id
left join customers on booksales.customer_id = customers.id
left join authors on books.author_id = authors.id
left join translators on books.translator_id = translators.id
left join editors on books.editor_id = editors.id
where booksales.date >= ?1 and booksales.date <= ?2
union all select 'Total', SUM(booksales.quantity), avg(booksales.price), SUM(booksales.quantity * booksales.price), '' ,'', '', '', '', '' from booksales
where booksales.date >= ?1 and booksales.date <= ?2",
, true, startDate, endDate
)