Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


El 30/07/12 2:08, Dan escribió:
Mark Stanton wrote:
Keys are intended for the internal workings of the database, they are
not meant to be
used like this.

What you want is the WHERE clause, or occasionally the HAVING clause,
matching or
excluding rows based on their data.

Keys are NOT data and should not be used as such.

Regards Mark Stanton One small step for mankind...

      I have a table, Reading, that contains three fields: ID, Date, and
Meter. Date is the
date the meter is read, and Meter is the meter reading.
      I want to know how much electricity (KWH used) I have used each
month. The query below will provide that information:

SELECT "Ending"."Date", "Ending"."Meter" -"Beginning"."Meter" AS "KWH
Used" FROM "Power". "Reading" AS "Beginning" LEFT JOIN "Power".
"Reading" AS" Ending" ON "Ending"."ID" =1 + "Beginning"."ID"

      Perhaps you are right about keys being intended for the internal
workings of the database. While I don't have an example of one key being
the multiple of the other key, it is possible. It just might not have
any practical applications.

--Dan


I have used a sentence like next with Firebird, but I don't know if your database lets to use SELECT like a field.

SELECT R_End.Date,
         (SELECT R_Beg.Date FROM Reading AS R_Beg WHERE R_Beg.Date
           = (SELECT DISTINCT MAX(R_Look.Date) FROM Reading AS R_Look
               WHERE (R_Look.Date < R_End.Date))) AS Beginning_Date
       R_End.Meter, (R_End.Meter -
         (SELECT R_Beg.Meter FROM Reading AS R_Beg WHERE R_Beg.Date
           = (SELECT DISTINCT MAX(R_Look.Date) FROM Reading AS R_Look
               WHERE (R_Look.Date < R_End.Date)))) AS KwH_used
 FROM Reading as R_End


(SELECT DISTINCT MAX(R_Look.Date) FROM Reading AS R_Look
               WHERE (R_Look.Date < R_End.Date))
Search the maximum date before the actual row date, which lets to get the previous values to the actual row date.

Miguel Ángel.

 * Inglés - detectado
 * Inglés
 * Español
 * Gallego
 * Italiano

 * Inglés
 * Español
 * Gallego
 * Italiano

 <javascript:void(0);>

--
For unsubscribe instructions e-mail to: users+help@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.