If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help me on SQL query for counting and display data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-10, 05:55
bh_hensem bh_hensem is offline
Registered User
 
Join Date: Jun 2009
Posts: 18
Help me on SQL query for counting and display data

Hi..

could somebody hep me about my query ?..

I want to display and count some values from the 2 tables.But I do not know how to count the records and display the result in different column of the output.

I have try to execute the query and i got an error message as below:-

Code:
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 34

Execution Time : 00:00:00:000
Transfer Time  : 00:00:00:000
Total Time     : 00:00:00:000
Below is my query:-
Code:
SELECT 
cs.request_id AS "JOB REQUEST NO",
cs.target_sla_sdate AS "TARIKH",
cs.target_sla_stime AS "MASA",
pt.FieldID2 AS "NAMA FAIL",
MIN(TRIM(pt.FieldID6)) AS "AKAUN MULA", 
MAX(TRIM(pt.FieldID6)) AS "AKAUN AKHIR", 
COUNT(pt.JobTIcketID) AS "JUMLAH AKAUN",
(SELECT (SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1
      AND  pt.FieldID3 BETWEEN "94" AND "195") AS "TOTAL RM2.00",
      
(SELECT (SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1
      AND  pt.FieldID3 BETWEEN "34" AND "93") AS  "TOTAL RM1.00",
      
(SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1
      AND  pt.FieldID3 BETWEEN "94" AND "195") AS "TOTAL RM0.75",
      
(SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1 AND (SUBSTR(TRIM(pt.FieldID2),20,2) = "PC" 
      OR SUBSTR(TRIM(pt.FieldID2),20,2) = "PB")) AS "TOTAL RM 0.40",
      
(SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1
      AND  (SUBSTR(TRIM(pt.FieldID2),20,2) = "PA")) AS "TOTAL RM0.30",
      
(SELECT COUNT(1) FROM packextra_trans pt, customerjobrequest cs  
      WHERE cs.JobTicketID = pt.FieldID1) AS "TOTAL POSLAJU"

FROM packextra_trans pt, customerjobrequest cs 
WHERE cs.JobTicketID = pt.FieldID1
AND cs.request_id = "201001-011" 
GROUP BY pt.JobTicketID
;
Otherwise, is it a good way to do the calculation or do you a better solution.

Please help me.

Thank you,
Baharin
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On