题目链接:点击打开链接
题目大意:略。
解题思路:注意:COUNT(NULL) = 0、COUNT(非NULL) = 1。
AC 代码
--解决方案(1) SELECTS.buyer_idFROMSalesSJOINProductPONS.product_id=P.product_idGROUPBYS.buyer_idHAVINGCOUNT(IF(P.product_name='S8',TRUE, NULL)) >=1ANDCOUNT(IF(P.product_name='iPhone',TRUE, NULL)) =0--解决方案(2) SELECTDISTINCTRS1.buyer_idFROM (SELECTbuyer_idFROMSalessJOINProductpONs.product_id=p.product_idWHEREproduct_name='S8') RS1LEFTJOIN(SELECTbuyer_idFROMSalessJOINProductpONs.product_id=p.product_idWHEREproduct_name='iPhone') RS2ONRS1.buyer_id=RS2.buyer_idWHERERS2.buyer_idISNULL