Using SQL queries

Discuss the spreadsheet application
Post Reply
tonyman
Posts: 109
Joined: Wed Mar 23, 2011 12:03 am

Using SQL queries

Post by tonyman »

Hey!

I just loaded a SQLite database into OO Calc. But now, how do I enter a query into one of my cells? I tried =SELECT count(*) FROM test; but that didn't work.

Image

I found this article in the wiki, but it only seems to cover the setup.

Thanks!
OpenOffice 3.3.0 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31285
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Using SQL queries

Post by Villeroy »

You add queries to the database and use them exactly like tables.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tonyman
Posts: 109
Joined: Wed Mar 23, 2011 12:03 am

Re: Using SQL queries

Post by tonyman »

I don't understand. In cell A1, I want the result of SELECT count(*) FROM activities WHERE name='Anne';. In A2, I want SELECT count(*) FROM activities WHERE name='Siren';. How is this done?

Thanks!
OpenOffice 3.3.0 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31285
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Using SQL queries

Post by Villeroy »

1) A Base query
SELECT "Name",COUNT(*) FROM "Table" GROUP BY "Name"
selects all counts for all names.

2) A data pilot does the same.

3) SELECT COUNT(*) FROM "Table" WHERE "Name" = :pName
Prompts for the name on each refresh.

4) A form can be used for parameter substitution: http://user.services.openoffice.org/en/ ... 427#p96427

5) A macro to update an input range with a query comosed in a cell: http://user.services.openoffice.org/en/ ... 6847#p6847
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tonyman
Posts: 109
Joined: Wed Mar 23, 2011 12:03 am

Re: Using SQL queries

Post by tonyman »

I still don't understand. All I want is to get the result of this query:

Code: Select all

SELECT count(*) FROM activities WHERE name='Anne';
from my ODBC connected SQLite file - into cell A1.

I cannot simply enter this query into my input line as a function?

I also don't understand why I'd need for wizards, forms and macros for this purpose.
OpenOffice 3.3.0 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31285
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Using SQL queries

Post by Villeroy »

Simply put it into your Base document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tonyman
Posts: 109
Joined: Wed Mar 23, 2011 12:03 am

Re: Using SQL queries

Post by tonyman »

Cool!

But - once I get the result of a query, how do I link it to a cell (as opposed to just copy / drag-and-drop), so that when I bring in a new version of my SQLite file, my cells get automatically updated?
OpenOffice 3.3.0 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31285
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Using SQL queries

Post by Villeroy »

Exactly like you pull in the table. Drag the query icon from the left pane of the data source window into a sheet. This imports a column label and a value into an import range. menu:Data>Refresh re-runs the query.
[Tutorial] Using registered datasources in Calc
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
tonyman
Posts: 109
Joined: Wed Mar 23, 2011 12:03 am

Re: Using SQL queries

Post by tonyman »

I really appreciate it man. Have a great day!
OpenOffice 3.3.0 on Windows 7
Post Reply