0

I am new to MySQL and need help with a query Here is some sample data with columns:

modelid styleid sequence
19463   316811  0
19463   316812  1
19463   316813  2
19463   316814  3
19463   316920  4
19463   316921  5
19727   318010  0
19727   318011  2
19727   318012  1
19727   318013  3
19884   320053  0
19884   320054  1
19884   320055  2
19884   320056  3
19998   321302  0
19998   321303  1
19998   321304  2
19998   321305  3
19998   321306  4
19998   321307  5
19998   321308  6
19998   321309  7

I need to get one styleid for every modelid, preferably with a sequence of 0 or 1, but the sequence does not really matter, it can be random.

The Best result would be something like this, CANT USE sequence = 0 as a where clause though:

modelid styleid sequence
19463   316811  0
19727   318010  0
19884   320053  0

Thanks

4

2 回答 2

0

尝试这个::

要么你可以使用group by喜欢::

Select modelid, styleid, sequence from myTable group by modelid

或者你可以使用DISTINCT

Select DISTINCT modelid, styleid, sequence from myTable
于 2013-07-21T17:10:34.840 回答
0

尝试这个

SELECT modelid, MAX(styleid),MIN(sequence)
FROM myTable 
GROUP BY modelid
于 2013-07-21T17:13:07.217 回答