trial balance are transformed into a series of SQL statements, which vary according to the database design. The details of the above procedure along with the relevant SQL statements need be explained in the context of the three Models as given below : Model-I : The following series of SQL statements retrieve a record set for producing trial balance when database design for Model-I is used. (a) To find the total amount by which the accounts have been debited : In order to ascertain the total amount by which every transacted account has been debited, the SELECT clause need to have two fields: one code to identify the transacted account and another to generate the total by which such account has been debited. This is achieved by using Debit field of Vouchers table and finding the sum of amount corresponding to each of the transacted accounts.
The FROM clause relies upon Vouchers table to get the data source. The GROUP BY clause specifies the field on the basis of which grouping of record set is formed. This grouping is necessary in SQL when aggregate query is used to generate summary information. The summing of amount is obtained by using aggregate function, Sum( ).
This function, as already explained, uses a field with data type Number, as an input argument and returns its sum as output. Accordingly, the following SQL statement is formed : SELECT Debit AS Code, Sum( amount ) AS Total FROM vouchers GROUP BY debit; In the above SQL statement, the GROUP BY clause retrieves the rows of vouchers table accounts-wise because the debit field refers to account code. As a result, the Sum( ) computes the sum of amount of a particular debit account and reports against Debit account of SELECT clause. This SQL statement is saved as Query 01for its subsequent use.
The total of debit amount in this query is given by Total field with positive amounts. (b) To find the total amount by which the accounts have been credited : In order to ascertain the total amount by which every transacted account has