Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

query question

 
   Database Forums (Home) -> Technology and Theory RSS
Next:  47  
Author Message
bayon86

External


Since: Dec 22, 2004
Posts: 9



(Msg. 1) Posted: Sat Oct 08, 2005 10:49 pm
Post subject: query question
Archived from groups: comp>databases>theory (more info?)

I'm using MySQL. I have a table that looks like this:

+-----+---------------------+---------------------+
| cid | opened | closed |
+-----+---------------------+---------------------+
| 1 | 2005-10-09 10:12:30 | 2005-10-09 11:37:36 |
| 2 | 2005-10-10 11:12:45 | 0000-00-00 00:00:00 |
| 3 | 2005-10-10 12:33:15 | 0000-00-00 00:00:00 |
| 4 | 2005-10-11 10:36:16 | 0000-00-00 00:00:00 |
| 5 | 2005-10-12 11:55:22 | 0000-00-00 00:00:00 |
+-----+---------------------+---------------------+

What I want as a query result is the total number of rows in 'opened'
and the total number of rows in closed that have a date assigned, i.e.
opened=5, closed=1. I'm relatively new to MySQL, and I can't for the
life of me get a handle on this one. Can this be done with a single
query? Do I need to make 'closed' a separate table?

Thanks very much in advance for any and all suggestions.

 >> Stay informed about: query question 
Back to top
Login to vote
user2311

External


Since: Dec 22, 2004
Posts: 286



(Msg. 2) Posted: Thu Oct 13, 2005 8:55 pm
Post subject: Re: query question [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"cruiserweight" wrote in message

> I'm using MySQL. I have a table that looks like this:
>
> +-----+---------------------+---------------------+
> | cid | opened | closed |
> +-----+---------------------+---------------------+
> | 1 | 2005-10-09 10:12:30 | 2005-10-09 11:37:36 |
> | 2 | 2005-10-10 11:12:45 | 0000-00-00 00:00:00 |
> | 3 | 2005-10-10 12:33:15 | 0000-00-00 00:00:00 |
> | 4 | 2005-10-11 10:36:16 | 0000-00-00 00:00:00 |
> | 5 | 2005-10-12 11:55:22 | 0000-00-00 00:00:00 |
> +-----+---------------------+---------------------+
>
> What I want as a query result is the total number of rows in 'opened'
> and the total number of rows in closed that have a date assigned, i.e.
> opened=5, closed=1. I'm relatively new to MySQL, and I can't for the
> life of me get a handle on this one. Can this be done with a single
> query? Do I need to make 'closed' a separate table?
>
> Thanks very much in advance for any and all suggestions.
>

Try this:

select
count (all opened) as opened,
count (all closed) as closed
from your_table;

This should do what you want, provided that MYSQL accepts this construct,
treats the "all" keyword the same way other systems do, and recognizes the
dates that are all zeroes as "missing data", better known as NULL.

 >> Stay informed about: query question 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
SQL Query Question. - X-No-Archive:yes I thought I'd see if you guys can help me with an SQL query that even Oracle admins couldn't solve without using an Oracle only function DECODE. I don't have DECODE on the DBMS I'm using, so I thought maybe the PhD SQL theorists may be...

Question on Multiplicity - Imagine you were knocking up a simple table of animals and their predominant colors. Something of the order: ---------------------- animal | color ---------------------- swan | white lion | yellow oranguatan | orange..

Could Someone help me with this theory question ?????? - Can some one please help me with this b+ tree problem as i have just started database and need help to answer these questions thanks very much in advance I really need help now Storage Problem A company maintains the following information : On..

Fast SQL Question - If I use like and I want to find all emails in hotmail that have at least one char before the '@' and after the '.' Is this the right command where EmailAddress like '%_@hotmail._%' Thanks

Searching question - How would someone be able to search through like 1.5 million records looking for a specific piece of text in a field without having to do a linear search through each record, given the fact that they do not have any information about the other fields in....
   Database Forums (Home) -> Technology and Theory All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]