473,394 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Nesting aggregates/subqueries v. derived tables

13
Hi again,

I could use some help and have not been able to come to grips with what I need to do to make this work.

I have a table of theories and votes and I want to return the percent to total of 'yes' votes. Here's what I have so far, which doesn't work:

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(tentries.vote) AS CountOfvote,count(tentries.theory) as countoftheory
  2. FROM tentries
  3. GROUP BY tEntries.vote, tentries.theory
  4. ORDER BY tEntries.vote,tentries.theory; 

This doesn't work because ultimately I need two things to render the percentage, the total number of votes on the query and the total number of yes votes. This just gives me a breakdown of number of each type of vote for each theory.

What I want is:

The number of yes votes:
select count(tentries.vote) as CountTrueVotes, tentries.theory
From tentries where tentries.vote = true ;

AND....
The count of each theory:
select count(tentries.theory) as CountOfTheories

AND...
The percentage of true votes to total:
Select counttruevotes/countoftheories as OverallYesVotes


Can someone help understand how to nest these together--I've looked into subqueries and derived tables but I'm having a hard time understanding which I need here, and how these fit together.

Very much appreciated!

Thank you!
Rosey
Jul 27 '07 #1
1 1546
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT DCount("[vote]","tentries", "[vote] = 'yes'") As TotalCount, Count(vote) AS CountOfvote, theory, TotalCount/CountOfvote As PercentVote
  2. FROM tentries
  3. WHERE vote = "yes"
  4. GROUP BY theory; 
  5.  
Aug 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Emanuele D'Arrigo | last post by:
Hi everybody! I hope you can gimme a hand with this: I just found out that the server I'm writing some code for only has MySQL 3.23.55 which unfortunately doesn't support subqueries (and dumb me...
0
by: Patrick Crowley | last post by:
I'm creating a tool to browse a database of movie listings. The browser pulls up 25 results at a time, and you can page through them using 'Next' and 'Prev' tools. Pretty basic stuff. Here are...
2
by: Kevin | last post by:
While converting SQL statements for a database change, I discovered a big performance hit in MYSQL with subqueries vices Sybase. I'm hoping that someone might be able to help me understand why? ...
6
by: J Belly | last post by:
Hi, all: This is probably a simple problem, but, as an SQL newbie, I'm having a little trouble understanding multi-joins and subqueries. I have the following tables and columns: ...
6
by: Saiyan Vejita | last post by:
I have the following SELECT query, the results of which I would delete from the table they're pulled from: SELECT A.* FROM SalesOrderPartPrices A WHERE EXISTS( SELECT 'Exists' FROM...
1
by: cindy | last post by:
Get data into datatable, add to dataset dsSearch " Get data into datatable, add to dataset dsSearch Using In-Memory SQL Engine join the tables and select the filenames from the join, add to...
2
by: CSN | last post by:
Is there much difference between using subqueries and separating out them into separate queries? __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building...
1
by: Garris, Nicole | last post by:
We've actually implemented this kind of thing in a different DBMS. The physical design consists of a single "organization" table that's something like: Org_key (primary key) Org_type (group,...
0
debasisdas
by: debasisdas | last post by:
Using Subqueries ================== The sub query is often referred to as a nested SELECT, Sub - SELECT, or inner SELECT statement. The sub query executes once before the main query. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.