Ask a Question related to Coldfusion Database Access, Design and Development.
-
Knum #1
Union or Join or Nested Select - Can't Remember
Its been along time since I have had to write tsql from the hip so any help
would be greatly valued. I have a table that contains Country, State, City and
I need to COUNT the total records for each. Example: United States (10)
---Texas (6) -------Dallas (4) -------Huston (2) ---New York (4) -------New
York (1) -------Buffalo (3) United Kindom(8) ---England (6) -------London(4)
-------Cork(2) ---Scotland (2) -------Fife (2) Or another way of looking at the
output: United States (10) ------------ Texas (6) ------------ Dallas (4)
United States (10) ------------ Texas (6) ------------ Huston (2) United States
(10) ------------ New York (4) ------- New York (1) United States (10)
------------ New York (4) ------- Buffalo (3) United Kindom(8) ------------
England (6) --------- London(4) United Kindom(8) ------------ England (6)
--------- Cork(2) United Kindom(8) ------------ Scotland(2) --------- Fife(2)
I know I am missing something really simple and I have done it before but I
just can't remember (two plus years the brain has been on the back burner) As
you can see the group by clause blows it up, I can't use the cfoutput group by
ether do to the fact that I am dumping the output into CF_MultiRelatedSelects
SELECT country&' ('&count(country)&')' as cln, state&'
('&count(state)&')' as cls, city&' ('&count(city)&')' as
clc FROM peole GROUP BY country, state,city ORDER BY country, state,city
Knum Guest
-
Nested join puzzler
I seem to have dug my way into a hole that's a bit over my head. I have a db laid out as shown here and I can query it with some very basic joins... -
Sub-Select vs. Join
Hi All, I have two tables. One table holds a list of states names. The other table holds the statesID the user slected along with there... -
MS Access Union Join not working w/ Coldfusion MX
Hope this makes sense. I'm new to this and trying to figure it out. I'm having problems getting a union join to work w/ Coldfusion MX 6.1. I have... -
sub select vs. join
Can anyone help convert the following sub-select into a join of some kind that will return the results described below? SELECT A.RST FROM A... -
JOIN/UNION question
OK basically I want to combine columns from two queries into a single table. I have one method that works but it feels like there is a simpler way to... -
zoeski80 #2
Re: Union or Join or Nested Select - Can't Remember
Hi Knum
I got these 2 working.
HTH
Zoe
QUERY 1
<CFQUERY NAME="queryName" ...>
SELECT country & '(' & count(country) & ')' as Country_Count,
'' as State_Count,
'' as City_Count
FROM peole
GROUP BY Country
UNION ALL
SELECT '' as Country_Count,
state & '(' & count(state) & ')' as State_Count,
'' as City_Count
FROM peole
GROUP BY State
UNION ALL
SELECT '' as Country_Count,
'' as State_Count,
city & '(' & count(city) & ')' as City_Count
FROM peole
GROUP BY City
ORDER BY Country_Count, State_Count, City_Count
</cfquery>
<CFDUMP VAR="#queryName#" LABEL="query 1">
QUERY 2
<CFQUERY NAME="queryName" ...>
SELECT 'Country' as FieldType, Country as FieldValue, count(country) as
FieldCount
FROM peole
GROUP BY country
UNION ALL
SELECT 'State' as FieldType, State as FieldValue, count(State) as FieldCount
FROM peole
GROUP BY State
UNION ALL
SELECT 'City' as FieldType, City as FieldValue, count(City) as FieldCount
FROM peole
GROUP BY City
ORDER BY FieldType, FieldValue, FieldCount
</cfquery>
<CFDUMP VAR="#queryName#" LABEL="query 2">
zoeski80 Guest



Reply With Quote

