newbie SQL questions...

newbie SQL questions...

am 26.01.2007 10:00:45 von Niel Darren

Hi,

I am a total newbie with SQL-statements, but hope you can help me, i have a
few questions:

1. How can i get the number of rows/records in a table with a SQL statement
?

2. I have a record looking like this:
ID, TIMESTAMP (hh:mm:ss), datastring

Is it possible with a SQL-statement to for example extract all records
between one timestamp to another in that format or should i convert it into
a unixtimestamp instead for simplicity ?

3. Is it possible to do calculations ? i have another table with: ID,
TIMESTAMP, graph x-point value
Then i want to instruct it to extract from one time to another, and give
me the average of all theese values (only asking if i can do it with SQL, if
not i can do it with code ofcourse).

Do you have a link to a PDF or similar resource that is useful for a SQL
newbie so i could get an insight in SQL - as i said, i am not much into it.

Thanks alot.

Re: newbie SQL questions...

am 26.01.2007 10:29:24 von Shion

Niel Darren wrote:
> Hi,
>
> I am a total newbie with SQL-statements, but hope you can help me, i have a
> few questions:
>
> 1. How can i get the number of rows/records in a table with a SQL statement
> ?

As you are using php, you have *_num_rows() (replace the '*' with the SQL
server type you are using).

You can of course use COUNT(*) in the SQL SELECT.


> 2. I have a record looking like this:
> ID, TIMESTAMP (hh:mm:ss), datastring

This should work:
SELECT * FROM table WHERE timecolumn>20050517120000 AND timecolumn<20060517120000;

There are other date related ways to do it too, just check the online manual
at mysql.com.


> 3. Is it possible to do calculations ? i have another table with: ID,
> TIMESTAMP, graph x-point value
> Then i want to instruct it to extract from one time to another, and give
> me the average of all theese values (only asking if i can do it with SQL, if
> not i can do it with code ofcourse).

SELECT AVG(graph_x_poin) FROM table;


> Do you have a link to a PDF or similar resource that is useful for a SQL
> newbie so i could get an insight in SQL - as i said, i am not much into it.

http://dev.mysql.com/doc/refman/5.0/en/


--

//Aho

Re: newbie SQL questions...

am 26.01.2007 11:04:34 von Captain Paralytic

On 26 Jan, 09:00, "Niel Darren" wrote:
> Hi,
>
> I am a total newbie with SQL-statements, but hope you can help me, i have a
> few questions:
>
> 1. How can i get the number of rows/records in a table with a SQL statement
> ?
either SELECT COUNT(*) FROM table
or if you are using the MyISAM engine SHOW TABLE STATUS LIKE 'table'
>
> 2. I have a record looking like this:
> ID, TIMESTAMP (hh:mm:ss), datastring
TiIMESTAMPs are usually 'YYYY-MM-DD HH:MM:SS', if you are only storing
hh:mm:ss then it is a TIME. When you do your query between 2 times, it
will then return values between those times for all days. Is that what
you want?

>
> Is it possible with a SQL-statement to for example extract all records
> between one timestamp to another in that format or should i convert it into
> a unixtimestamp instead for simplicity ?
>
> 3. Is it possible to do calculations ? i have another table with: ID,
> TIMESTAMP, graph x-point value
> Then i want to instruct it to extract from one time to another, and give
> me the average of all theese values (only asking if i can do it with SQL, if
> not i can do it with code ofcourse).
>
> Do you have a link to a PDF or similar resource that is useful for a SQL
> newbie so i could get an insight in SQL - as i said, i am not much into it.
>
> Thanks alot.