473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Using same field as alias and using the count in the query.

I am trying to create a small report and what I want to do is pull the same field in a query 4 times and I am trying to alias the field and also have it just count the number of records, not give me the actual record. An example of what I am trying to do is:

SELECT Status AS Approved = Count(Status)
FROM AppStatus
WHERE Status = 'A'
GO
SELECT Status AS Conditioned = Count(Status)
FROM AppStatus
WHERE Status = 'I'

but instead of it actually pulling the records, I want it to just count the records for each, so if Approved has 4 records, I want it to show 4 not all 4 records and if Conditioned has 9 records, I want to see 9 instead of all 9 records, but I also want to see 4 for the Approved field as well. I don't even know if this is possible, but I think my logic is somewhat right so far, I just don't know where to put the count so the results would look like this.


NAME____Approved_____Declined_____Conditioned___To tal
Bob................4.....................2........ ............9......................15

instead, what I have been getting is

NAME____Approved____Declined____Conditioned____Tot al
Bob........1............0.............0..........1
Bob........0............1.............0..........1
Bob........0............1.............0..........1
Bob........1............0.............0..........1
Bob........1............0.............0..........1
Bob........1............0.............0..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1
Bob........0............0.............1..........1



Does this make any sense? Thanks for any help that might come my way. It will be very appreciated. By the way, I am not wanting to get the ..... I had to use those to try to line up my numbers with my columns.
May 5 '11 #1
2 2051
Rabbit
12,516 Expert Mod 8TB
You need to use the group by clause. And then pivot it (if MySQL supports pivoting) to get the values across the top.
May 5 '11 #2
I will look at the group by clause as well as the pivot. I have never used or seen this, so I am going to see what I can find on it. Thanks.
May 5 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Nicolae Fieraru | last post by:
Hi All, I have a query, Select Count(BoolField) from tblMyTable, Where BoolField = true. If I run the query by itself, it returns the number of true records I want to use the result of that...
0
by: Vikramaditya Singh | last post by:
i have made a crystal repoirt using field defination methos (.ttx). Now i am passing a dataset to it at runtime but no records is beiing displayes this is the code i am using to creating dataset...
12
by: briansmccabe | last post by:
Does anyone have a good approach to displaying in PHP a simple COUNT query that is performed on a table in a MySQL db? Thanks
6
by: dBNovice | last post by:
Hey group, I am trying to do a count of the number of papers in a table. The table has a PaperID that differentiates each paper , e.g. 004.1. Some papers are reused. The reused paper is given...
1
by: OtheymAverian | last post by:
For the past few days I have been trying to figure out how to add a Ranking field to a sorted query so I can then reference the rank in a report. I am using Access 2002 and have no SQL experience,...
0
by: greg | last post by:
I'm doing a join on a table with a cross tab query and I only want to select the last field in the crosstab query but I get a syntax error, even if I reference it with the correct dynamically...
1
by: Shmedlap | last post by:
I can't put a hyperlink field into a crosstab query. The Crosstab row is set to Row Heading. If I set the Total row to Group By, then I get nonsense. If I set the Total row to First then I get a...
4
by: GladGad | last post by:
I am not a real well versed query writer and therefore am having some problems figuring out how to write a parameter query where I want to input a partial name. I have tried a few different things,...
3
WyvsEyeView
by: WyvsEyeView | last post by:
This seems like it should be so easy to do. I have a table, called tblTopics. Each topic can have one or more instances, contained in a table called tblTopicInst. tblTopics is bound to a form called...
1
by: mfletcher | last post by:
Hi I have a query which calculates a large number of fields for each record, i don't want all of the fields present in the datasheet view only those fields selected by the user in a list box(or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.