如何比较两个不同表中的字段 [英] How to compare fields from two different tables

查看:57
本文介绍了如何比较两个不同表中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我比较两个不同表中的两个字段.
我有2张桌子:
1)Prescribed_Medicines(PID(PK),medCode(FK),UnitPrice,数量)和
2)NHIS_Medicines(medcode(PK),单价,数量)

我想将Prescribed_Medicines表中的单价字段和数量与
进行比较 NHIS_Medicines表中的单价和数量字段

请我需要帮助,请帮助我

Please help me to compare two fields from two different tables.
I have 2 tables:
1) Prescribed_Medicines(PID(PK),medCode(FK), UnitPrice, Quantity) and
2) NHIS_Medicines(medcode(PK), UnitPrice, Quantity)

I want to compare the fields UnitPrice, and Quantity in Prescribed_Medicines table with
fields UnitPrice and Quantity in NHIS_Medicines table

Please i need help, please help me

推荐答案

如果两个表中都有medCode,问题出在哪里?
下面的示例显示了如何从2个表中获取具有相同medCodes和UnitPrices的记录.
If you have medCode in both tables, where is the problem?
The example below shows how to get records from 2 tables with equal medCodes and UnitPrices.
SELECT PM.medCode AS PM_medCode, PM.UnitPrice AS PM_UnitPrice, PM.Quantity AS PM_Quantity, NM.medcode AS NM_medcode, NM.UnitPrice AS NM_UnitPrice, NM.Quantity AS NM_Quantity
FROM Prescribed_Medicines AS PM INNER JOIN NHIS_Medicines AS NM ON PM.mdeCode = NM.medCode
ORDER BY PM.medCode
WHERE PM.UnitPrice = NM.UnitPrice


这篇关于如何比较两个不同表中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆