I have the table
我有桌子
itemuid | category ----------------------------- 1 | 3 2 | 3 3 | 21 4 | 3 5 | 3 6 | 21 7 | 3 -----------------------------
I now want to select the itemuid
with the category
21
before itemuid
5
. The itemuid
is the only information I've got from which I need to search backwards.
我现在想要在itemuid 5之前选择类别为21的itemuid .siteuid是我从中获得的唯一信息,我需要向后搜索。
Can anyone tell me how the select
and where
query must look like? Thanks.
任何人都可以告诉我如何选择和查询必须是什么样子?谢谢。
6 个解决方案
#1
1
SELECT * FROM table
WHERE itemuid < 5 AND category = 21
ORDER BY itemuid DESC
LIMIT 1
#2
0
SELECT itemuid from notablenameinquestion where category=21 AND itemuid < 5 order by itemuid LIMIT 1;
#3
0
SELECT s.itemuid
FROM (SELECT itemuid
FROM yourTable
WHERE yourConditions
ORDER BY category DESC) s
WHERE ROWNUM = 1
#4
0
If i understand you correctly:
如果我理解正确的话:
Select Top(1) itemid from table_name where categoryid=21 and itemid<5
#5
-1
If "before" means the biggest itemuid
that is still smaller than 5, then:
如果“之前”表示仍然小于5的最大项目,则:
select max(itemuid) from tablename where itemuid < 5 and category = 21
#6
-2
If I'm understanding you correctly, this should work:
如果我正确理解你,这应该有效:
SELECT itemuid FROM table_name WHERE category=21 and itemuid < 5
#1
1
SELECT * FROM table
WHERE itemuid < 5 AND category = 21
ORDER BY itemuid DESC
LIMIT 1
#2
0
SELECT itemuid from notablenameinquestion where category=21 AND itemuid < 5 order by itemuid LIMIT 1;
#3
0
SELECT s.itemuid
FROM (SELECT itemuid
FROM yourTable
WHERE yourConditions
ORDER BY category DESC) s
WHERE ROWNUM = 1
#4
0
If i understand you correctly:
如果我理解正确的话:
Select Top(1) itemid from table_name where categoryid=21 and itemid<5
#5
-1
If "before" means the biggest itemuid
that is still smaller than 5, then:
如果“之前”表示仍然小于5的最大项目,则:
select max(itemuid) from tablename where itemuid < 5 and category = 21
#6
-2
If I'm understanding you correctly, this should work:
如果我正确理解你,这应该有效:
SELECT itemuid FROM table_name WHERE category=21 and itemuid < 5