E
E
EVOSandru62016-02-14 04:51:50
PostgreSQL
EVOSandru6, 2016-02-14 04:51:50

Why does a postgres query return an array?

Good afternoon,
There are 3 tables connected in series:
categories ( id, name )
products ( id, category_id, name )
tarifs ( id, product_id, price, percent )
It is necessary, having category id , to find the lowest tariff among all rooms, if If there is a percentage in the field ( percent is not NULL ), then you need to convert the value. I made a sketch, but for some reason I have an array at the output. Even if I set Distinct , then the output value is not the minimum tariff from the set:

SELECT
        DISTINCT
          CASE
            WHEN percent IS NOT NULL
              THEN
                MIN(price) +
                (MIN(price) * percent / 100)
            ELSE
              MIN(price)
          END
            as min_price
            FROM
                        tarifs
            LEFT JOIN
                        products
            ON
               	 		tarifs.product_id = products.id
      LEFT JOIN
                        categories
            ON
               	 		products.category_id = categories.id
      WHERE
            categories.id = :id
      GROUP BY
            tarifs.id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2016-02-14
@EVOSandru6

Then you do the grouping when you need order by + limit 1?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question