SELECT * , GRP.URLNAME AS GRPURLNAME, (CASE GRP.BRACODE WHEN 8 THEN 99 WHEN 9 THEN 98 WHEN 10 THEN 97 WHEN 3 THEN 96 WHEN 5 THEN 95 WHEN 11 THEN 94 ELSE 50 END)AS BRAORDER FROM M_SHOHINGRP GRP LEFT OUTER JOIN M_JYOKEN JYO ON JYO.GRPCODE = GRP.GRPCODE LEFT OUTER JOIN M_BRAND BRA ON BRA.BRACODE = GRP.BRACODE LEFT OUTER JOIN M_ECHIN ECH ON ECH.GRPCODE = GRP.GRPCODE LEFT OUTER JOIN ( SELECT GRPCODE, COUNT(HINCODE) AS COUNTS FROM M_HIN WHERE ECTORIFLG = 1 AND HINTEISHI IS NULL GROUP BY GRPCODE ) CNT ON CNT.GRPCODE = GRP.GRPCODE WHERE JYO.MAKCODE = 2 AND JYO.SHACODE = 42 AND JYO.KATCODE = 1 AND GRP.HYOJIFLG = 1 AND NOT COALESCE( CNT.COUNTS, '0') = 0 AND GRP.BNRCODE = 1 AND GRP.BRACODE = 12 ORDER BY BRAORDER DESC,GRP.BRACODE,GRP.SORTORDER DESC,GRPNAME
SELECT * , GRP.URLNAME AS GRPURLNAME, (CASE GRP.BRACODE WHEN 8 THEN 99 WHEN 9 THEN 98 WHEN 10 THEN 97 WHEN 3 THEN 96 WHEN 5 THEN 95 WHEN 11 THEN 94 ELSE 50 END)AS BRAORDER FROM M_SHOHINGRP GRP LEFT OUTER JOIN M_JYOKEN JYO ON JYO.GRPCODE = GRP.GRPCODE LEFT OUTER JOIN M_BRAND BRA ON BRA.BRACODE = GRP.BRACODE LEFT OUTER JOIN M_ECHIN ECH ON ECH.GRPCODE = GRP.GRPCODE LEFT OUTER JOIN ( SELECT GRPCODE, COUNT(HINCODE) AS COUNTS FROM M_HIN WHERE ECTORIFLG = 1 AND HINTEISHI IS NULL GROUP BY GRPCODE ) CNT ON CNT.GRPCODE = GRP.GRPCODE WHERE JYO.MAKCODE = 2 AND JYO.SHACODE = 42 AND JYO.KATCODE = 1 AND GRP.HYOJIFLG = 1 AND NOT COALESCE( CNT.COUNTS, '0') = 0 AND GRP.BNRCODE = 4 AND GRP.BRACODE = 12 ORDER BY BRAORDER DESC,BRA.SORTORDER DESC,GRP.SORTORDER DESC,GRPNAME