佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1255|回复: 1

几个关于mysql的问题

[复制链接]
发表于 8-2-2007 10:24 AM | 显示全部楼层 |阅读模式
最近我开始买mysql的书来自学,我照这他们的练习来做,可是想来想去都想不到以下的几个COMMAND要怎样开始写

1. print the name of the patient that cost the most money (i.e sum of all treatments cost was hightest)最高时P4,因为他要付29.97
2. print the name of the patient that did not have treatment 11111. 我做了,但它显示所有的patient names,我要的答案是Alex, Albert, Sue, Richard 的名字
3.print the nme of the INS company that had to pay the most money.
4.print the name of the MD that prescibed the treatments that cost the most money

以下是我做的tables
INS

MDS

MP

TREATMENT

PATIENTS


有人指导下吗
回复

使用道具 举报


ADVERTISEMENT

发表于 15-2-2007 06:07 PM | 显示全部楼层
试试以下的statements。可能不是完全对也不是最好的答案。希望会对你有帮助。

1。
SELECT p.pcode AS patient_code, p.name AS patient_name, SUM(mp.price) AS total FROM TREATMENT AS t LEFT JOIN PATIENTS AS p ON (t.pcode = p.pcode) LEFT JOIN MP AS mp ON (t.mdcode = mp.mpcode) GROUP BY patient_code, patient_name ORDER BY total DESC LIMIT 1;

2。
SELECT pcode AS patient_code, name AS patient_name FROM PATIENTS WHERE pcode not in (SELECT pcode FROM TREATMENT WHERE mpcode = '1111');

3。
SELECT ins.inscode AS ins_code, ins.name AS ins_name, SUM(mp.price) AS total FROM TREATMENT AS t LEFT JOIN PATIENTS AS p ON (t.pcode = p.pcode) LEFT JOIN INS AS ins ON (p.inscode = ins.inscode) LEFT JOIN MP AS mp ON (t.mdcode = mp.mpcode) GROUP BY ins_code, ins_name ORDER BY total DESC LIMIT 1;

4。
SELECT mds.mdcode AS mds_code, mds.name AS mds_name, SUM(mp.price) AS total FROM TREATMENT AS t LEFT JOIN MDS AS mds ON (t.mdcode = mds.mdcode) LEFT JOIN MP AS mp ON (t.mpcode = mds.mpcode) GROUP BY mds_code, mds_name ORDER BY total DESC LIMIT 1;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-8-2025 04:22 AM , Processed in 0.108951 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表