473,378 Members | 1,354 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,378 software developers and data experts.

help in sql query

the relations are

MEMBERSHIP(membership_number (pk), cover_type(pk),
start_date(pk), end_date)

PERSON(person_number(pk), surname, initials, street_address, suburb, ,

DOCTOR(doctor_number(pk), surname, initials, street_address, suburb)

PROVIDED-SERVICE(person_number(pk), doctor_number(pk), service_date(pk),

REBATE(service_number(pk), cover_type(pk), refund)

SERVICE(service_number(pk), service_name, service_description)

i am struggling in this query can any one help me

1)List the service-names and maximum refund payable for those services
which have been provided to every person who has visited a doctor.

this query asks for info about those services provided to every person
who has visited a doctor. For each such services, list the name of the
service and the maximum refund for that service (i.e. the same service
can have many different refunds, only list the highest refund). Maximum
refund therefore refers to the maximum for each such service, not a
maximum across all services.

2)what is the name and address of the doctor, or doctors, who have
provided services to the smallest non-zero number of individual
patients (regardless of the number of services they provided to
each patient)?

i dont the answers for these queries if anyone help me in this regard i
would be so thankful
Posted via http://dbforums.com
Jul 20 '05 #1
2 1362
Please include proper DDL with your posts, including constraints and
datatypes. Here are my solutions based on assumptions about your foreign

SELECT S.service_name, SUM(R.refund) AS maximum_refund
FROM Rebate AS R
JOIN Service AS S
ON R.service_number = S.service_number
JOIN Provided_Service AS P
ON S.service_number = P.service_number
JOIN Doctor AS D
ON P.doctor_number = D.doctor_number
GROUP BY S.service_name
WHERE D.doctor_number = @doctor_number

SELECT D.doctor_number, D.surname, D.initials, D.street_address, D.suburb,
COUNT(DISTINCT P.person_number) AS no_of_patients
FROM Doctor AS D
JOIN Provided_Service AS P
ON D.doctor_number = P.doctor_number
GROUP BY D.doctor_number, D.surname, D.initials, D.street_address, D.suburb
FROM Provided_Service
GROUP BY doctor_number)

David Portas
Please reply only to the newsgroup
Jul 20 '05 #2

thanks for your reply

SELECT S.service_name, MAX(R.refund) AS maximum_refund

FROM Rebate AS R

JOIN Service AS S

ON R.service_number = S.service_number

JOIN Provided_Service AS P

ON S.service_number = P.service_number

JOIN Doctor AS D

ON P.doctor_number = D.doctor_number

GROUP BY S.service_name

WHERE D.doctor_number = @doctor_number

here i dont understand the last line can you explain it a bit

i think the query will bring up the maximum refund for those services
which doctor attended.

my question is maximum refund for those services for a person who
attends a doctor and

the value of refund which is dependend on the cover_type of a member
Posted via http://dbforums.com
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
by: Steve Patrick | last post by:
Hi All You guys are my last hope, despite spending money on books and hours reading them I still can not achieve the results I need. I have designed a database in Access 2000 based on 1 table,...
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
by: mcmahonb | last post by:
Hey people... I've been searching this forum for a few hours and even though this topic has been went over from many different angles; I cannot seem to figure out how to make things work on my...
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
by: Jo | last post by:
Hi there, I'm Jo and it's the first time I've posted here. I'm in process of creating a database at work and have come a little unstuck.....I'm a bit of a novice and wondered if anyone could...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.