我有四张桌子
1)组件登录
id com_name co_logo
------ ---------------------------------- ------------------
1 UNFAN default_logo.png
2 T&P default_logo.png
3 Elliot default_logo.png
117 walkin default_logo.png
118 12 starShipping Management default_logo.png
119 ABS Marine default_logo.png
120 Accord Marine Management default_logo.png
121 Admiral Marine default_logo.png
122 AET default_logo.png
123 Air Borne Rec.Pvt.Ltd. default_logo.png
125 Apex Marine default_logo.png
2)医学
Med_Id G_Name B_Name
------ ------------------------------- ---------------------
1 Acetylsalicylic acid Aspirin, aspro
2 Aciclovir Zovirax, acyclovir
3 Amoxicillin + clavulanate Augmentin, co-amoxcylav
4 Artemether + Lumifantrine Riamet
5 Azithromycin Zithromax
6 Cetirizine Zyrtec
7 Ciprofloxacin Ciproxin , Cipro
8 Dizepam Valium
9 Docusate with senna (for equivalent) Coloxi
10 Doxycyline Neo-Dagracyline, Unodox,
3)m_shipinv公司
Id MedId ShipId
------ ------ --------
1 1 2918
4 2 2918
5 3 2918
6 4 2918
7 5 2918
9 6 2918
10 7 2918
11 8 3095
4)待定
id co_id vessel_name
------ ------ ---------------------------
2918 123 Sima Sadaf
2930 123 Aegean Odyassey
2925 123 Apj Jad
2923 123 Astor
2924 123 Astro
2941 123 Discovery
2937 123 Disney Fantasy
2919 123 Disney Cruise
2940 123 Disney Dream
2933 123 Disney Magic
2934 123 Disney Wonder
3095 125 sdare
我只想展示公司拥有的船只。。。我只想显示西玛·萨达夫。。。因为一家公司有许多船只,而西马萨达夫公司的船只编号是123。所以只有公司拥有的船只才应该展示。不应展示船舶sdare,因为它不是公司的一部分
Vessel_ID Vessel_Name Total_Medicine
---------- ---------- ----------------
2918 Sima Sadaf 7
最佳答案
试试这个:
SELECT vs.id as Vessel_ID, vs.vessel_name, COUNT(DISTINCT m.id) Total_Medicine
FROM t_vesselmaster vs
INNER JOIN m_shipinv m ON vs.id = m.ShipId
INNER JOIN comp_login cl ON vs.co_id = cl.id
WHERE vs.co_id = 123
GROUP BY vs.vessel_id, vs.vessel_name;
关于mysql - 获取多个联接中的行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27311592/