SQL查询 - 不等于

时间:2015-08-02 01:31:12

标签: sql oracle

使用select * from books where (category != 'computer') AND retail < 30.00; 表,编写一个查询,列出有关那些非计算机书籍且零售价不超过30美元的书籍的所有信息。

这就是我所拥有的:

"computer"

但它一直在类别部分给我<!DOCTYPE html> <html> <head> <script type = "text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script> <script> $(document).ready(function(){ var embargo_top = 0; var embargo_left = 0; var allowed = true; var to_delete = ""; function initialize_board(){ var random_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; var positions = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen"]; while (random_array.length > 0){ var rand = random_array[Math.floor(Math.random() * random_array.length)]; var pos = positions[Math.floor(Math.random() * positions.length)]; document.getElementById(pos).innerHTML = rand; var index = random_array.indexOf(rand); random_array.splice(index, 1); var pos_index = positions.indexOf(pos); positions.splice(pos_index, 1); } var div = "#" + positions[0]; var coords = $(div).position(); embargo_top = coords.top; embargo_left = coords.left; to_delete = positions[0]; $(document.getElementById(positions[0])).hide(); } initialize_board(); function determine_solvability(){ var num_inversions = 0; var array_inc = []; var possibilities = ["one", "two", "three", "four"]; var to_add = 0; for(i = 0; i<possibilities.length; i++){ var tmp = document.getElementById(possibilities[i]); var id = tmp.id; alert(id); var to_append = tmp.innerHTML; array_inc.push(to_append); console.log(array_inc); num_inversions = check_tile(id, array_inc, num_inversions); } console.log(num_inversions); } determine_solvability(); function check_tile(num, array_inc, num_inversions){ console.log(array_inc); var div = document.getElementById(num); var val = div.innerHTML; if (val == 1){ return num_inversions; } else{ var count = 1; for(i = 0; i < array_inc.length; i++){ var arraryTmp = parseInt(array_inc[i]); var intVal = parseInt(val); if (arraryTmp < intVal){ count += 1; } } num_inversions += (val - count); console.log(num_inversions); return num_inversions; } }; }); </script> </head> <body> <table style = "width: 100%"> <tr> <td><div class = "tile" id = "one"></div></td> <td><div class = "tile" id = "two"></div></td> <td><div class = "tile" id = "three"></div></td> <td><div class = "tile" id = "four"></div></td> </tr> <tr> <td><div class = "tile" id = "five"></div></td> <td><div class = "tile" id = "six"></div></td> <td><div class = "tile" id = "seven"></div></td> <td><div class = "tile" id = "eight"></div></td> </tr> <tr> <td><div class = "tile" id = "nine"></div></td> <td><div class = "tile" id = "ten"></div></td> <td><div class = "tile" id = "eleven"></div></td> <td><div class = "tile" id = "twelve"></div></td> </tr> <tr> <td><div class = "tile" id = "thirteen"></div></td> <td><div class = "tile" id = "fourteen"></div></td> <td><div class = "tile" id = "fifteen"></div></td> <td><div class = "tile" id = "sixteen"></div></td> </tr> </table> </body> </html>

非常感谢任何人的帮助。

4 个答案:

答案 0 :(得分:0)

您的查询在MySql上运行正常...您使用的是什么DBMS,您标记了mysql SQLServer ...

 select * from books where (category != 'computer') AND retail < 30.00;

检查this fiddle

编辑:所以你正在使用sqlPlus ...我找不到那个小提琴,我会尝试使用:

 select * from books where category <> 'computer' AND retail < 30.00;

如果sqlPlus用于Oracle 11g R2,请检查this other fiddle,您的查询似乎按预期工作。

答案 1 :(得分:0)

您对数据库区分大小写吗?我会从结果集中复制文本并将其粘贴到Category过滤器的位置。尝试这样的事情。代码在T-SQL中,请根据需要进行调整

SELECT * from books 
WHERE UPPER(RTRIM(category)) != N'COMPUTER'
AND retail < 30.00;

值得检查如果以上操作无效,您有多少类别。会给你一些线索。

SELECT DISTINCT category
FROM books 
ORDER BY category

答案 2 :(得分:-1)

尝试使用<>代替!= 如果您的数据库区分大小写,则您需要为每个排列设置一个条件,您可以使用NOT IN ('Computer','computer')操作。

答案 3 :(得分:-1)

尝试:

[1:len(iterable) - 1]

在Open Office Base中,我需要按照@Aaron的建议使用NOT IN。

SELECT * FROM books WHERE ( category != 'computer' AND retail < 30 )