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

help very urgent


the relations are

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

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

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

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

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

SERVICE(service_numbe(pk)r, service_name, service_description)

the cover_types are single, couple, family

the question is

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 only those services provided to every person

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.

i came with the following query

SELECT s.service_name, MAX(r.refund) as maximum_refund

FROM rebate r,service s,provided_Service ps,doctor d

WHERE r.service_number = s.service_number AND

s.service_number = ps.service_number AND

ps.doctor_number = d.doctor_number

GROUP BY s.service_name;

any help in this regard is very much appreciated .

thank you.
--
Posted via http://dbforums.com
Jul 20 '05 #1
3 1397
If I've understood you correctly the only modification required to your
query is the additional criteria to include only services that have been
provided to everyone, correct?

If so, try this:

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
WHERE S.service_number IN
(SELECT service_number
FROM Provided_Service
GROUP BY service_number
HAVING COUNT(DISTINCT person_number) =
(SELECT COUNT(*)
FROM Person))
GROUP BY S.service_name

If this doesn't answer your question then please post DDL (CREATE TABLE
statements) for your tables, include some sample data as INSERT statements
and show an example of your required result.

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

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

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #3
Here's a better alternative to my first effort:

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, S.service_number
HAVING COUNT(DISTINCT P.person_number) =
(SELECT COUNT(*)
FROM Person)

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

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

Similar topics

28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
8
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for...
7
by: zeyais | last post by:
Here is my HTML: <style> ..leftcolumn{float:left;width:300px;border: 1px solid #ccc} ..rtcolumn{float:left;width:600px;border: 1px solid #ccc} </style> <body> <div class="leftcolumn"...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: Rainer Queck | last post by:
Hello NG, I am currently confronted with the task to equip a vs2005 project with context sensitive online help (F1). Reading through the MSDN-Library I found out about the "HelpProvider" class,...
9
needhelp123
by: needhelp123 | last post by:
Can any one send me a quick sort simple logic pogram... its very urgent urgent
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
1
by: psantosh12 | last post by:
Hello Frnds Please need help to resolve error.......... it is very very urgent........ The error is Runtime Error Description: An application error occurred on the server. The current custom...
2
by: =?Utf-8?B?U2NvdHRSYWREZXY=?= | last post by:
I'm creating a doc project for my c# program. I've done this before but this time sonething is wrong. I build my doc project and is succeeds but when I open the help file, there is no documentation...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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
agi2029
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.