473,324 Members | 2,124 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,324 software developers and data experts.

How do you combine 2 items in a Group By while doing a Crosstab query?

anoble1
245 128KB
I have a Crosstab query that I am working on. So, for my Column Heading I want to use this 1 Field that has 5 options in it. Right now if I put in the Criteria "Car" or "Truck" I get 2 columns, 1 column for car and 1 column for truck. Is there a way I can just total those both up in 1 column. So the Field will show a total of Car & Truck instead of separating it?
Oct 31 '22 #1
7 10728
NeoPa
32,556 Expert Mod 16PB
Hi ANoble.

I suspect there is a way. Why don't you explain what you're doing with all the relevant detail and then the answer will make a lot more sense. We can express it in terms that you, and others reading the question, will be able to understand more easily.
Oct 31 '22 #2
anoble1
245 128KB
Please see the attached. Right now I am having to separate in the Group By in the Crosstab query with the criteria Car or Truck.
On the right in the attachment you will see Proposed where I would like to Sum those 2 selections in the "Type" field.

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(tblInformation.[Dealer Name]) AS [CountOfDealer Name]
  2. SELECT tblInformation.[State]
  3. FROM tblInformation
  4. WHERE (((tblInformation.[Type])="Car" Or (tblInformation.[Type])="Truck"))
  5. GROUP BY tblInformation.[State]
  6. PIVOT tblInformation.[Type];

Attached Images
File Type: png Annotation 2022-10-31 130030.png (5.1 KB, 241 views)
Oct 31 '22 #3
NeoPa
32,556 Expert Mod 16PB
It seems like you don't need a Crosstab at all then if I understand you correctly. What about :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [State]
  2.        , Count([Type]) AS [Car/Truck]
  3. FROM     [tblInformation]
  4. WHERE    [Type] In('Car','Truck')
  5. GROUP BY [State]
  6. ORDER BY [State]
Oct 31 '22 #4
anoble1
245 128KB
My fault there. Later once I get this figured out I need to add another field and do the same type thing beside the “Type” field
Nov 1 '22 #5
NeoPa
32,556 Expert Mod 16PB
If you need multiple sets of groupings within your possible [Type] columns then Crosstab on a subquery that connects the values you require :
Expand|Select|Wrap|Line Numbers
  1. SELECT [State]
  2.      , Switch([Type]='Car','Car/Truck'
  3.                     ,'Truck','Car/Truck'
  4.                     ,'Motorcycle','Bike'
  5.                     ,'Scooter','Bike'
  6.                     ,True,[Type]) As [NewType]
  7.      , [OtherField(s)]
  8. FROM   [tblInformation]
You're right that the answer will change when the question does, so we do need to know the question in order to give the most appropriate answer. The latter suggestion should work in most cases but the earlier suggestion will only work in the scenario as previously described. It's more straightforward though so would be preferable in situations where it works.
Nov 1 '22 #6
Arushi
7 Nibble
You cannot combine two items in a Group By while doing a Crosstab query.
Nov 2 '22 #7
NeoPa
32,556 Expert Mod 16PB
Arushi:
You cannot combine two items in a Group By while doing a Crosstab query.
I'm afraid I don't even know what you're trying to say :-S

Is this a response to anything (any post?) in particular?

Are you saying that PIVOT & GROUP BY clauses can never be used together in the same set of SQL? That would appear to be wrong if so.
Nov 2 '22 #8

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

Similar topics

3
by: John | last post by:
I've read several prior posts in this group about using nz() to convert null values to zero; however, I'm not sure how/where to implement this function in my crosstab query. The crosstab query...
8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: jb | last post by:
Query Help Please- I want to make: name date value lee sept 40 lee oct 27 lee nov 50 dan dec 50 jen jan 30
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
0
by: priyankas | last post by:
I am getting this error when doing a SELECT statement . COM.ibm.db2.jdbc.DB2Exception Message is: CLI0 :109E String data right truncation. SQLSTATE=22001 Can anyone help me out with this?
3
by: russellhq | last post by:
Hi, I'm fairly new to access and have a little trouble with a crosstab query I've setup. I have a main form where the user selects a project name and below in a subform, a crosstab query is...
6
by: Peter Herath | last post by:
I want to create a dynamic report using a crosstab query...... pls someone look into my attached example database and help me out to do the report generation.... example is like dis...: there...
0
by: Peter Herath | last post by:
I want to create a custormizable report . For an example, there's a form with four combo boxes and two of them having database tables columns/field names as values in the combo box(one for select row...
4
by: rdsandy | last post by:
Hi, I have some code below in VBA for Access 2003 which is on a button called "RentalCrosstabPercTtlQtyMonthLoc_Click". This is a crosstab query which brings up rental items down the side, who...
2
by: Jim Devenish | last post by:
I wish to create a crosstab query as the record source for a report. It needs to count data between selected dates which are entered by the user in a popup window. The following Select query...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.