db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bernt M. Johnsen" <Bernt.John...@Sun.COM>
Subject Re: A SQL question , how to show calculated fields in Rows not in columns
Date Wed, 08 Feb 2006 13:15:40 GMT
>>>>>>>>>>>> Legolas Woodland wrote (2006-02-08 16:14:58):
> Hi
> Thank you for reading my post.
> imagine that i have :
> select count(userID) ,count (siteID) from users,websites
> it will show one record that contain two columns , each column represent 
> one of the count value

Your proposal will just give you two equal numbers (unless there are
null values) which both will count the numbers of rows in the join
between users and websites.

You probably meant

select (select count(userID) from users),
       (select count(siteID) from sites) from somedummytable;

> now i want to show two record with one column , indeed i need this to 
> pass the query to a charting system . the chart will just use first 
> column of each rows.
> so i need to have two rows with one column to use that charting
> system.

(select 'users',count(userID) from users) union 
(select 'sites',count(siteID) from sites)

might do what you need.

PS: There are several good textbooks covering SQL available from
Amazon and other bookstores.

Bernt Marius Johnsen, Database Technology Group, 
Staff Engineer, Technical Lead Derby/Java DB
Sun Microsystems, Trondheim, Norway

View raw message