I am saying this query below, only pull the pub column and it does not pull
the sub. I want the pub and sub to pull if there is a match from Info_pub
table.
TRANSFORM Sum(INFORMATION.[ITEM#]) AS [SumOfITEM#]
SELECT IIf([INFORMATION].[Pub]=[Info_Pub].[Pub],[INFORMATION].[Pub],"Other")
AS Pub_, Sum(INFORMATION.[ITEM#]) AS Totals
FROM INFORMATION LEFT JOIN Info_Pub ON INFORMATION.Pub = Info_Pub.Pub
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
GROUP BY IIf([INFORMATION].[Pub]=[Info_Pub].[Pub],[INFORMATION].[Pub],"Other")
PIVOT INFORMATION.Sub;
:
I do not follow what you are asking.
After seeing your raw data I know Ierred in using Sum instead of Count in
two of the queries. Here are the corrected queries ---
hoachen_1
SELECT "Total" AS Pub_, INFORMATION.Sub, Count(INFORMATION.[ITEM#]) AS Totals
FROM INFORMATION
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
GROUP BY "Total", INFORMATION.Sub;
hoachen_2
SELECT Information.Pub, Information.Sub, Count(Information.[ITEM#]) AS
ItemCount
FROM Information
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
GROUP BY Information.Pub, Information.Sub
UNION ALL SELECT hoachen_1.Pub_, hoachen_1.Sub, hoachen_1.Totals
FROM hoachen_1;
TRANSFORM Sum([hoachen_2].[ItemCount]) AS [SumOfItemCount]
SELECT IIf([hoachen_2].[Pub]=[Info_Pub].[Pub],[hoachen_2].[Pub],"Other") AS
Pub_, Sum([hoachen_2].[ItemCount]) AS Totals
FROM hoachen_2 LEFT JOIN Info_Pub ON [hoachen_2].Pub=Info_Pub.Pub
GROUP BY IIf([hoachen_2].[Pub]=[Info_Pub].[Pub],[hoachen_2].[Pub],"Other")
PIVOT [hoachen_2].Sub;
--
Build a little, test a little.
:
The...i thinking so slow!!!! new table for the pub that i want to match.
Genius...well, since you are so good with this, I have one more request to
this. Now, the query only match up the Pub(new table: “Info_pubâ€) with the
Pub at table “informationâ€. I also need the Pub from “Info_pub†table that
match the Sub at the “information†table and display it just like Pub.
For example:
The Pub (MCG also can be Sub)
The Sub (Pearson also can be Pub)
Information Table data
Item# Author Pub Sub
6633814 JOHNSTON OOSTING+A Vital
6633810 NORTHSTAR FRISTSTAR Vital
6633801 *NORTHSTAR FRISTSTAR Vital
6633670 SULLIVAN PEARSON Vital
66336666 SULLIVAN LIGHT PEARSON
6666630 Smith S+S Vital
6633650 *SPARKCHART SPARKNOTES Vital
66336466 *SPARKCHART SPARKNOTES Vital
6621640 BISTNER ELSEV Vital
66216366 AEHLERT ELSEV Vital
6671762 ABEL PEARSON Courses
6671760 HUSTED PEARSON Courses
6665577 HUSTED PEARSON Courses
6672248 PANDE Light MCG
66686631 DALRYMPLE Light AEGYPAN PR
6668666 CRAM 101 TXBK MCG Courses
66638066 STERN Light PENG
66528166 WILSON Light JOSSEY
6647830 HAYES Light PENG
66478266 TAPSCOTT Light PENG
:
The need for Info_pub is to use in the
IIf([INFORMATION].[Pub]=[Info_Pub].[Pub],[INFORMATION].[Pub],"Other")
so that any Pub not in list is displayed as 'Other'. By th way you need
'Total' in it also.
One query totals and then is put in a union with query selecting orignal
data and finally a crosstab query.
--
Build a little, test a little.
:
Thank you for your help! Now, i am confuse, why need to create a table named
"Info_pub"? All the data were in one table, i can't change that
So, the below queries will show the total in row? What about the statement
you wrote?
:
I omitted to creat table named Info_Pub with list of Pub not deemed Other.
Create these three queries to have Totals row at the bottom --
hoachen_1
SELECT "Total" AS Pub_, INFORMATION.Sub, Sum(INFORMATION.[ITEM#]) AS Totals
FROM INFORMATION
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
GROUP BY "Total", INFORMATION.Sub;
hoachen_2
SELECT Information.Pub, Information.Sub, Information.[ITEM#]
FROM Information
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
UNION ALL SELECT hoachen_1.Pub_, hoachen_1.Sub, hoachen_1.Totals
FROM hoachen_1;
TRANSFORM Sum([hoachen_2].[ITEM#]) AS [SumOfITEM#]
SELECT IIf([hoachen_2].[Pub]=[Info_Pub].[Pub],[hoachen_2].[Pub],"Other") AS
Pub_, Sum([hoachen_2].[ITEM#]) AS Totals
FROM [hoachen_2] LEFT JOIN Info_Pub ON [hoachen_2].Pub=Info_Pub.Pub
GROUP BY IIf([hoachen_2].[Pub]=[Info_Pub].[Pub],[hoachen_2].[Pub],"Other")
PIVOT [hoachen_2].Sub;
--
Build a little, test a little.
:
Your post had Vital & Vitals. Your SQL had Count and needed Sum.
TRANSFORM Sum(INFORMATION.[ITEM#]) AS [SumOfITEM#]
SELECT IIf([INFORMATION].[Pub]=[Info_Pub].[Pub],[INFORMATION].[Pub],"Other")
AS Pub_, Sum(INFORMATION.[ITEM#]) AS Totals
FROM INFORMATION LEFT JOIN Info_Pub ON INFORMATION.Pub = Info_Pub.Pub
WHERE (((INFORMATION.Sub)="Vitals") AND ((INFORMATION.Author) Not Like
"*[*]*")) OR (((INFORMATION.Sub)="Courses") AND ((INFORMATION.Author) Not
Like "*[*]*")) OR (((INFORMATION.Sub)="light") AND ((INFORMATION.Author) Not
Like "*[*]*"))
GROUP BY IIf([INFORMATION].[Pub]=[Info_Pub].[Pub],[INFORMATION].[Pub],"Other")
PIVOT INFORMATION.Sub;
It will take a little more work to get the total row at the bottom.
--
Build a little, test a little.
:
Below is the SQL view:
Right now, it shows all the Pub Name but I would like to specific which pub
name i want to show and then those i did not choose to show will be group
into "Other". I hope this help explain
TRANSFORM Count([INFORMATION].[ITEM#]) AS [CountOfITEM#]
SELECT [INFORMATION].Pub, Count([INFORMATION].Pub) AS Totals
FROM [INFORMATION]
WHERE ((([INFORMATION].Sub) Like "Vital") AND (([INFORMATION].Author) Not
Like "*[*]*")) OR ((([INFORMATION].Sub) Like "Courses")) OR
((([INFORMATION].Sub) Like "light"))
GROUP BY [INFORMATION].Pub
PIVOT [INFORMATION].Sub;
Let say, I want these shows:
Pub COURSES LIGHT VITAL Totals
ABC CLIO C 11 11
BEDFORD F 146 6 152
CENGAGE CO 1893 26 1919
GRAY PUB 38 38
OTHER 1936 3 155 2094
TOTAL 3975 3 236 4214
Currently show like this:
Pub COURSES LIGHT VITALS Totals
ABC CLIO C 11 11
ACSI COURS 3 3
AMSCO S 92 92
BAKER+TAY 1 1
BEDFORD F 146 6 152
CENGAGE CO 1893 26 1919
GRAY PUB 38 38
GUILFORD C 20 20
CENGAGE CO 1893 26 1919
HUMAN K CO 1 1
JONES+B CO 43 12 55
LIGHTNIN S 3 12902