Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
| 邮政编码 | 价值 | 标题 | ---------------------------- | 1 | 0 | 标题 1 | | 2 | 1 | 标题 2 | | 3 | 1 | 标题 3 | | 4 | 0 | 标题 4 | | 5 | 4 | 标题 5 |
我试图从我的表中选择两个随机不同的行。有没有办法用 SQL 做到这一点?
我试过了
SELECT postid FROM table WHERE postid > 0.9 ORDER BY RAND( ) LIMIT 2
试试这个
SELECT DISTINCT postid FROM tablename ORDER BY RAND() LIMIT 2
是的,与andDISTINCT一起使用:ORDER BY RAND()LIMIT
DISTINCT
ORDER BY RAND()
LIMIT
SELECT DISTINCT postid, value, title FROM yourtable ORDER BY RAND() LIMIT 2