postgres
1SELECT 2 3 tbl_test_A.satsuei_no, 4 tbl_test_A.name, 5 tbl_test_A.birthday, 6 tbl_test_A.age, 7 tbl_test_A.sex, 8 tbl_test_A.kensa_date, 9 tbl_test_A.kensa_time, 10 tbl_test_A.modality, 11 tbl_test_A.image_no, 12 tbl_test_A.dantai_code, 13 tbl_test_A.shozoku_code, 14 tbl_test_A.senryou, 15 tbl_test_A.gousha_no, 16 tbl_test_A.gishi_name, 17 tbl_test_A.pkey 18 19FROM tbl_test AS tbl_test_A 20 21INNER JOIN ( 22 SELECT 23 karute_no, 24 pkey AS max_pkey 25 FROM tbl_test 26 WHERE valid_flg ='1' 27 28 ) AS tbl_test_B 29 30ON 31tbl_test_A.karute_no = tbl_test_B.karute_no 32AND 33tbl_test_A.pkey = tbl_test_B.max_pkey 34 35WHERE 36tbl_test_A.valid_flg = '1' 37and 38tbl_test_A.kensa_date = '2018-11-06' 39 40ORDER BY max_pkey asc
tbl_testテーブルでvalid_flgが「1」のpkeyが最大値のものを取得したいです。
現在はpkeyが最大値のものを取得できていません。
下記のSQLでどのようにすればいいでしょうか。
/--------------------------------------------------------/
/--------------------------------------------------------/
回答2件
あなたの回答
tips
プレビュー