Y
Y
youngpulse2015-09-01 18:17:37
SQL
youngpulse, 2015-09-01 18:17:37

SQL. How to determine if the value of a particular field is the same/different for rows during grouping?

Hello! :)
Tell me, please, the solution of the following problem: It is
necessary to group rows by several fields. The problem is that you also need to check if all the rows in one group have the same value for a particular field. If this value is the same, we are happy, everything is OK, if it is different, the formed group needs to change a certain field.
The trick is how exactly to determine that all rows in a group have the same/different flag value.
Thank you in advance for your response:)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
gimntut, 2015-09-01
@gimntut

You need to compare the minimum and maximum in a column.
If there are multiple values ​​in a column, then the minimum and maximum will not match.
And you also need to compare the quantity, because null is not taken into account when calculating minimums and maximums.
Example: sqlfiddle.com/#!9/7ec6a/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question