There are 3 tables:
scoreT
-----------------------
id_score | id_name | score
1 | 1 | 350
2 | 2 | 400
3 | 3 | 450
4 | 4 | 330
5 | 5 | 500
nameT
------------------------
id_name | name | id_country
1 | Bill | 1
2 | Ana | 2
3 | Ted | 2
4 | Ryan | 3
5 | Kyle | 3
countryT
id_country | country
1 | USA
2 | INA
3 | GER
So how to make query table like this?
country | count of name | average of Score | count name who have Score >= 400 | percentage of name who have Score >= 400 |
USA | 1 | 350 | 0 | 0
INA | 2 | 425 | 2 | 100
GER | 2 | 415 | 1 | 50
4 808 Luuk 1,047
Recognized Expert Top Contributor
ok, next SQL is untested, an syntax might not be valid in MSSQL - SELECT
-
X.country,
-
COUNT(X.id_name) AS count_of_name,
-
AVERAGE(X.score) AS averag_of_Score,
-
COUNT(X.bigger) AS higher_schore_than_400,
-
COUNT(X.bigger)/COUNT(X.id_name) AS percentage
-
FROM (
-
SELECT s.id_score, s.id_name, s.score, n.name, n.id_country, c.country, CASE WHEN s.score>=400 THEN 1 ELSE 0 END AS bigger
-
FROM scoreT s
-
INNER JOIN nameT n ON n.id_name=s.id_name
-
INNER JOIN countryT c ON c.id_country=n.id_country
-
GROUP BY country
-
) X
-
there is a warning "Characters found after end of SQL statement"
ADezii 8,834
Recognized Expert Expert
I was able to arrive at a solution but not within the context of a single Query, which was my original intention. I ended up using a Totals Query with two Calculated Fields and a Select Query to accomplish the task. Rather than go into a detailed explanation, I'll simply Post my Demo, and should you have any questions feel free to ask. This is, in my opinion, not the optimal solution, but until a better one comes along it is something to look at. Out of curiosity, this appears to be some form of homework assignment, is it? P.S. - Pay special attention to the Relationships among the three Tables which make it all work.
@ADezii
It's work for me now. Thanks
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Alan Little |
last post by:
I have a table with links, a log table to record clicks, and a vote table
to record votes on the links.
Is it possible to get the link data, the click count, vote count and vote
total in one query?
I can get the click count OK, but as soon as I add the vote count to the
query, it multiplies them; e.g. for a link with 14 clicks and 2 votes, it
tells me 28 for both figures. Here's the query:
|
by: jenkinsloveschicken |
last post by:
I am somewhat new to Access and have been tasked with creating a reporting database for my operation. The problem I am having is that I am needing to use the Count function to calculate total instances for each phone agent within the report, then use these counts to calculate a percentage for a report.
Sample recordset:
Specialist ID, Specialist Name, Brand Satisifaction, Specialist Satisfaction
111111 John Doe 4 ...
|
by: djflow |
last post by:
Hi!
II was wondering if you can help me with SQL query..
Below 7 separated select query works fine(only when they are retrieved separately)
But I want to combined them together and so that i can make report from my database on the one sheet rather than querying each select statement ( I will use MS Query from the Excel)
=========================================================
1)
select convert(varchar, create_date_time, 112) as Date,...
|
by: newnewbie |
last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our system and thinks I am omnipotent now and can extract any data out of it in the form he wants….The truth is, though I know SOME Access, I am not a programmer…and many queries that he wants me to do have a potential of being monstrous towers of...
|
by: Noorain |
last post by:
sir
i want a query which count total student. here 6 record of student. here one student two times entry. my result is total student 5. i can't do this.
my table is:
id stu_name dob
1 Saima 2009-02-01
2 Tanvir 2009-02-11
3 Saima 2009-02-01
4 Rumman 2009-02-01
| |
by: kkshansid |
last post by:
i hav a table with a column named result where values are either of the three
pass ,fail,absent
can i get multiple count in same row
like
select count(result=pass) as cp,count(result=fail) as cf,count(result=absent) as ca;
i know about three select count statements with three where clause
|
by: AndyB2 |
last post by:
Writing some VBA to call a make table query. It the make query is pulling data from a MS 2008 R2 SQL database then creating the data locally for processing. It works, but not when I call it out of the code below:
Private Sub CopyData_Click()
Dim dbo_Machine_a As QueryDef
Dim dbo_Machine_Hello As QueryDef
Dim dbo_Machine_World As QueryDef
Select Case MachineNameCombo
|
by: antjonz |
last post by:
I can create a query to count the total number of items in a table, but I need it to show me how many times each item occurs. For example, during the month of March my query shows me that 97 items were requested. I need to see the amount of times each item was requested that resulted in 97 items. I know there's something I need to do in the query itself, but I can't figure it out.
|
by: bwanty |
last post by:
Hi everybody
How can I get this query:
For each month (use dateofappointment) of 2010, show a count of appointments. Also show the count of diagnosed diseases, and a count of patients seen during the month.
I'm trying this query but it doesn't work , because I got same number for each count
SELECT COUNT(APPOINTMENT.APPOINTMENTID), COUNT(PATIENT.PATIENTID), COUNT(DIAGNOSED.DISEASEID)
FROM APPOINTMENT , PATIENT , DIAGNOSED , DISEASE ...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |