私はこのようなテーブルを持っているため2フィールドを使用して1つのフィールド:クエリPOSTGRESQL</strong><strong>に句
Column | Type | Modifiers
---------------+-----------------------------+-----------
id | smallint | not null
merchant_id | smallint | not null
batch_no | smallint | not null
私はこのようなクエリを持っているが:
select merchant_id , max(batch_no) from batch group by merchant_id
それは、このような値を返します。
merchant_id | max
-------------------+------
14 | 593
45 | 1
34 | 3
46 | 1
25 | 326
27 | 61
17 | 4
どのように各データのIDを取得できますか?上記のデータのIDは1の結果を得るためにどのようなクエリを使用できますか?
あなたもidを引き出す必要があるようです。あなたのケースでは、 'select id、merchant_id、max(batch_no)バッチグループby merchant_id'から – kobaltz
IDとmerchant_IDの関係は何ですか? SELECT * FROMバッチの最初の5行またはそれ以上の行をポストできますか? – Aaron