question

charanp avatar image
charanp asked

Pick a row with certain data from group by

I have following data in my tables

--------------------------------------------------------------------------
| S.No | name                    | quantity   | price        | sold_by   |
--------------------------------------------------------------------------
|bk005 | Book 1                  | 4          | 120          | XYZ       |
--------------------------------------------------------------------------
|bk007 | Book 2                  | 2          | 60           | XYZ       |
--------------------------------------------------------------------------
|bk009 | Book 2                  | 2          | 60           | ME        |
--------------------------------------------------------------------------
|bk011 | Book 1                  | 4          | 100          | ME        |
--------------------------------------------------------------------------


I am using GROUP BY clause get a unique book. But if price of a book I am selling is lesser than of other competitors then book with sold_by ME must be selected else any random row can be selected. Is there a way to achieve this?

mysqlgroup-by
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.