-4

I am trying to check if my ID = 4 is within the RESULTS from MySQL but not in the last row and you probably don't understand what I am asking for lol, let me explain now:

I have ID = 4 hard coded

I have MySQL SELECT statement LIKE:

SELECT * FROM TABLE WHERE GROUP_ID = 10 AND ID = 4 AND (LAST OF THE RECORD FROM THAT GROUP_ID IS NOT (!=) (NOT EQUAL) (IS DIFFERENT) THEN 4

Cannot explain it simpler

4

1 回答 1

0

我认为您正在寻找这样的查询:

SELECT
  yourtable.GROUP_ID,
  CASE WHEN
    SUM(yourtable.UID=s.max_uid AND yourtable.ID!=4)=1
    AND SUM(yourtable.UID!=s.max_uid AND yourtable.ID!=4)=0
  THEN 'okay' ELSE 'no' END
FROM
  yourtable INNER JOIN
  (SELECT GROUP_ID, MAX(UID) max_uid
   FROM yourtable
   GROUP BY GROUP_ID) s
  ON yourtable.GROUP_ID = s.GROUP_ID
GROUP BY
  yourtable.GROUP_ID

在此处查看小提琴。

于 2013-06-29T13:36:32.550 回答