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 > Informix > Informix Query Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-01-09, 11:59
Mahfuz Mahfuz is offline
Registered User
 
Join Date: Nov 2003
Location: Dhaka,Bangladesh
Posts: 86
Informix Query Problem

Dear Informix Experts,

I am very new in Informix database. Follwoing SQL is giving syntex error. Can any one please guide me where i made mistake?? Its urgent please help.


Select Distinct(Select count(status) From mmo where status = 1) As 'MMO Msg per Status 1',
(Select count(status) From mmo where status = 2) As 'MMO Msg per Status 2',
(Select count(status) From mmo where status = 3) As 'MMO Msg per Status 3',
(Select count(status) From mmo where status = 4) As 'MMO Msg per Status 4',
(Select count(status) From mmo where status = 5) As 'MMO Msg per Status 5',
(Select count(status) From mmo where status = 6) As 'MMO Msg per Status 6',
(Select count(status) From mmo where status = 7) As 'MMO Msg per Status 7',
(Select count(status) From mmo where status = 8) As 'MMO Msg per Status 8',
(Select count(status) From mmo where status = 9) As 'MMO Msg per Status 9',
(Select count(status) From mmo where status = 10) As 'MMO Msg per Status 10',
(Select count(status) From mmo where status = 11) As 'MMO Msg per Status 11',
(Select count(status) From mmo where status = 12) As 'MMO Msg per Status 12',
(Select count(status) From mmo where status = 13) As 'MMO Msg per Status 13',
(Select count(status) From mmo where status = 14) As 'MMO Msg per Status 14',
(Select count(status) From mmo where status = 15) As 'MMO Msg per Status 15',
(Select count(status) From mmo where status = 16) As 'MMO Msg per Status 16',
(Select count(status) From mmo where status = 17) As 'MMO Msg per Status 17',
(Select count(status) From mmo where status = 18) As 'MMO Msg per Status 18'from mmo Order by 1
__________________
hello
Reply With Quote
  #2 (permalink)  
Old 08-01-09, 17:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
replace what you have there with this --
Code:
SELECT status
     , COUNT(*) AS status_count
  FROM mmo 
 WHERE status BETWEEN 1 AND 18
GROUP
    BY status
ORDER
    BY status
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-02-09, 01:33
Mahfuz Mahfuz is offline
Registered User
 
Join Date: Nov 2003
Location: Dhaka,Bangladesh
Posts: 86
Dear r937 ,

As you replied

SELECT status
, COUNT(*) AS status_count
FROM mmo
WHERE status BETWEEN 1 AND 18
GROUP
BY status
ORDER
BY status

but i made the query to export record in such format with column name as:

MMO Msg per Status 1 MMO Msg per Status 2.........MMO Msg per Status 18
0 2 15

What i need to do? Please help
__________________
hello
Reply With Quote
  #4 (permalink)  
Old 08-02-09, 04:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by Mahfuz
What i need to do?
use a front-end language like php or asp to re-arrange the query results
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-02-09, 04:56
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Hi, although quite unefficient the real problem with:
Quote:
Select Distinct(Select count(status) From mmo where status = 1) As 'MMO Msg per Status 1',
(Select count(status) From mmo where status = 2) As 'MMO Msg per Status 2'
from mmo Order by 1
is that the columntag can't be a regular string. If you use
Code:
AS MMO_Msg_per_Status_x
as tags it will work. The columnheaders will be presented all lowercase though.

Regards,
Hans
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