<report>
<title>Customers by Country and State/Province (All)</title> 

	<!-- country -->
	<level> 
		<htmlstyle>heading</htmlstyle> 
		<sql>SELECT DISTINCT count(A.id) as total1, C.name as country from %%AGILE_DB_PREFIX%%account A  
				left join %%AGILE_DB_PREFIX%%country C on (A.country_id=C.id) 
		</sql>
		<criteria>A.site_id = %%DEFAULT_SITE%% AND A.country_id IS NOT NULL AND A.country_id!=0</criteria>
		<orderby>GROUP BY country ORDER BY total1 ASC</orderby>
		<indent>0</indent>
		<column>
			<display>Country:</display>
			<field>country</field>
			<aggregate>true</aggregate>
			<width></width>
			<format></format>
			<group_children_by>true</group_children_by>
			<visible>true</visible>
			<hide_dups>false</hide_dups>
			<sql></sql>
			<sql_criteria></sql_criteria>
			<condition></condition>
			<total>false</total>
			<total_format></total_format>
			<link></link>
		</column>
		<column>
			<display>Total Customers: </display>
			<field>total1</field>
		</column>	
		
		<!-- city -->
		<level> 
			<sql>SELECT DISTINCT C.name as country, count(A.id) as total2,  A.state as region from %%AGILE_DB_PREFIX%%account A  
					left join %%AGILE_DB_PREFIX%%country C on (A.country_id=C.id) 
			</sql>
			<criteria>A.site_id = %%DEFAULT_SITE%% and C.site_id = %%DEFAULT_SITE%% AND A.country_id IS NOT NULL AND A.country_id!=0</criteria>
			<orderby>GROUP BY region ORDER BY region ASC</orderby>
			<indent>30</indent> 	
			<column>
				<display>State/Province: </display>
				<field>region</field>
				<aggregate>true</aggregate>
				<width></width>
				<format></format>
				<group_children_by>true</group_children_by>
				<visible>true</visible>
				<hide_dups>false</hide_dups>
				<sql></sql>
				<sql_criteria></sql_criteria>
				<condition></condition>
				<total>false</total>
				<total_format></total_format>
				<link></link>
			</column>					
			<column>
				<display>Total  Customers: </display>
				<field>total2</field>
			</column>	
					
			<level> 
				<sql>SELECT DISTINCT A.state as region, C.name as country, A.company, A.email, CONCAT(A.first_name,' ', A.last_name) as name, CONCAT(address1,' ', address1,', ', city, ' ', state, ', ', zip ) as address from %%AGILE_DB_PREFIX%%account A
						left join %%AGILE_DB_PREFIX%%country C on (A.country_id=C.id) 
				</sql>
				<criteria>A.site_id = %%DEFAULT_SITE%% and C.site_id = %%DEFAULT_SITE%%  AND A.country_id IS NOT NULL AND A.country_id!=0</criteria>
				<orderby>ORDER BY company ASC</orderby>
				<indent>30</indent> >
				<column>
					<display>Contact</display>
					<field>name</field> 
				</column>
				<column>
					<display>Company</display>
					<field>company</field> 
				</column>				
				<column>
					<display>Address</display>
					<field>address</field> 
				</column>
				<column>
					<display>E-mail</display>
					<field>email</field>  
				</column>		
			</level> 
		</level>		  
	</level>	 
</report>
