Using SQL to shape chart data Home

Introduction
Welcome
System requirements
Licensing details
What is the registration
Using ASPRunner
Working with projects
Templates
What are templates
Cars
Classified ads
Events
Jobs
Knowledge base
News
Paypal
Real estate
Sporting
Vacation houses
Connecting to the database
Datasource tables
SQL query page
About SQL query designer
Query Designer
SQL
Results
Charts
Creating chart and setting parameters
Chart appearance
Using SQL to shape chart data
Reports
Creating report and setting parameters
Report totals and layout
Choose pages
Login page
User login settings
Advanced security settings
User group permissions
Fields order and totals
Miscellaneous settings
Choose theme
Visual Editor
About
Toolbars
Page Elements
"View as" settings
"Edit as" settings
Validation types
Lookup wizard
Events
Output directory settings
After you are done
FTP upload
FrontPage Publishing
Advanced topics
Connecting to database
Connecting to MS Access database
Connecting to MS SQL Server database
Connecting to FoxPro database
Connecting to MySQL database
Connecting to Oracle database
Connecting to MS Excel database
Connecting to CSV or Text file
Events
More about events
Global events
Table events
Page life cycle overview
Predefined actions
Send simple email
Send email with new data
Save new data in another table
Insert a record into another table
Check if specific record exists
Display a message on the Web page
Redirect to another page
Custom code
Sample code
Show list of customer orders
Check if start date is ealier than end date
Before deleting a record check if related records exist
Speed up data entry using events
Publishing ASP application to the remote Web server
Using third party FTP client to publish ASP pages to the remote Web server
Using FrontPage to publish ASP pages to the remote Web server
Demo account
What is the Demo Account?
Terms and Conditions
Master-details relationships
Using JOIN SQL queries
AJAX-based Functionality
ASPRunner session variables
Debugging tips
Template files processing rules (Files.txt)
Multilanguage support
Useful functions and links
Smarty templates
Stylesheets
Template language
Rich Text Editor plugins
How to control Inline Add/Edit functionality from script
Troubleshooting "Operation must use an updateable query" errors
ODBC
Upgrade Guide from ASPRunnerPro 4.0 and older
Frequently Asked Questions
Error: Operation must use an updateable query.
Error: Syntax error in UPDATE statement.
Error: Syntax error in INSERT INTO statement
Error: Login failed for user 'MACHINE_NAME\IUSR_MACHINE_NAME'
Error: Data type mismatch in criteria expression
Error: The Microsoft Jet database engine cannot open the file (unknown).
Error: Unable to open registry key 'Temporary (volatile) Jet DSN for process ...
Error: Data provider could not be initialized
Error: Invalid use of Null: 'Replace'
Error: Specified driver could not be loaded due to system error 5 (Oracle in OraHome92)
How can I add new ODBC Datasource
Error: Too many fields defined
Error: I enter correct login and password but receive Invalid Login error. I use SQL Server.
I cannot find ODBC Administrator applet on Windows 2000 machine
I cannot connect to my Excel (Access) database
Where can I download latest ODBC drivers
How to work with Access database stored on the remote computer?
Reserved Access, T-SQL, ODBC keywords.
Order ASPRunner online

 
  ASPRunner manual


Using SQL to shape chart data

 

Charts are all about visualizing your data. Charts need data fields that store numeric values however using aggregate functions you can build charts on any data.

Consider the following Orders table:

Customer

Country

Total

Andrew Peters

USA

$250

Katie Bradshow

Australia

$85

Jeff Simpson

USA

$150

Arnold Matteus

Germany

$120

Arnold Matteus

Germany

$160

Jeff Montgomery

GB

$150

Andrew Peters

USA

$65

Jeff Simpson

USA

$95

Luke Sohu

France

$40

Jeff Montgomery

GB

$120

Example 1: Total Sales per country

Query

select Country, sum(total) as STotal

from Orders

group by country

order by 2 desc

Results:

Country

Stotal

USA

$560

Germany

$280

GB

$270

Australia

$85

France

$40

Chart:

Example 2: Number of orders per country

Query:

select Country, count(total) as CTotal

from Orders

group by country

order by 2 desc

Results:

Country

CTotal

USA

4

Germany

2

GB

2

Australia

1

France

1

Chart:

 

Example 3: Shaping your data more complex way

This example shows how to use GROUP BY in conjunction with INNER JOIN. For example we have the following data and like to display a diagram that illustrates how many flags each client has.

clientid

flag

1001

Green

1001

Green

1001

Green

1001

Green

1001

Amber

1001

Amber

1001

Red

1002

Green

1002

Amber

1002

Amber

1002

Amber

1002

Red

1003

Green

1003

Amber

1003

Red

To shape our data we use the following SQL query

select a.clientid, a.green,b.red, c.amber

from (select count(flag) as green, clientid from sensorstatus

where flag='Green' group by clientid) a

inner join (select count(flag) as red, clientid from sensorstatus

where flag='Red' group by clientid) b on a.clientid=b.clientid

inner join (select count(flag) as amber, clientid from sensorstatus

where flag='Amber' group by clientid) c on a.clientid=c.clientid;

which gives us the following results:

clientid

green

red

amber

1001

5

1

2

1002

2

1

3

1003

1

1

1

Related info:

Interactive SQL tutorial

 

The CHM file was converted to HTML by chm2web software.