PDA

View Full Version : How can I get the result for the following SQL statement using JavaScript



asifakhtar
09-07-2010, 04:57 PM
Hi,
How can I get the result for the following SQL statement using JavaScript?

SELECT branch, region, referral, COUNT(DISTINCT LPS) FROM table GROUP BY branch, region, referral

Data:
Branch Client Referral Type LPS #
402036 402430 Psychological File Review 30
402036 402430 Psychological File Review 50
402049 402805 Chiropractic File Review 10
402049 402805 In-Home Assessment 20
402049 402806 Chiropractic File Review 30
402049 402806 Chiropractic File Review 20
402049 402806 Chiropractic File Review 10
402049 402806 Chiropractic File Review 10
402049 402807 Physiotherapy Assessment 10
402049 402807 Physiotherapy Assessment 10
402049 402807 Physiotherapy Assessment 20
402049 402808 In-Home Assessment 10
402049 402816 Chiropractic Assessment 50
402049 402827 Neurological File Review 40


Please note I have the data in ascending order.

The result should look like the following table.
Branch Client Referral Type LPS #
402036 402430 Psychological File Review 30
402036 402430 Psychological File Review 50
Psychological File Review Total 80
402430 Total 80
402036 Total 80
402049 402805 Chiropractic File Review 10
Chiropractic File Review Total 10
402049 402805 In-Home Assessment 20
In-Home Assessment Total 20
402805 Total 30
402049 402806 Chiropractic File Review 30
402049 402806 Chiropractic File Review 20
402049 402806 Chiropractic File Review 10
402049 402806 Chiropractic File Review 10
Chiropractic File Review Total 70
402806 Total 70
402049 402807 Physiotherapy Assessment 10
402049 402807 Physiotherapy Assessment 10
402049 402807 Physiotherapy Assessment 20
Physiotherapy Assessment Total 40
402807 Total 40
402049 402808 In-Home Assessment 10
In-Home Assessment Total 10
402808 Total 10
402049 402816 Chiropractic Assessment 50
Chiropractic Assessment Total 50
402816 Total 50
402049 402827 Neurological File Review 40
Neurological File Review Total 40
402827 Total 40
402049 Total 240
Grand Total 320

Thanks