where和order by

数字条件:

SQL> select salary from employees where employee_id=100;

字符串大小写敏感:

SQL> select last_name, salary from employees where last_name=‘King‘;

SQL> select table_name, tablespace_name from user_tables where table_name=‘EMPLOYEES‘;

lower()

日期格式敏感:

select sysdate from dual

SQL> alter session set nls_date_format=‘RR-Mon-dd‘;

SQL> select last_name from employees where hire_date=‘2006-05-23‘;

SQL> select last_name from employees where hire_date=to_date(‘2006-05-23‘, ‘yyyy-mm-dd‘);

区间查询:

SQL> select last_name from employees where salary>=3400 and salary<=4000;

SQL> select last_name from employees where salary between 3400 and 4000;

SQL> select last_name from employees where salary between 3000 and 5000 and department_id=50;

in:

SQL> select last_name from employees where department_id=30 or department_id=40 or department_id=50;

SQL> select last_name from employees where department_id in (30, 40, 50);

通配符:

SQL> select last_name, job_id from employees where job_id like ‘%\_MAN‘ escape ‘\‘;

null作为条件:

SQL> select last_name from employees where commission_pct is null;

SQL> select last_name from employees where commission_pct is not null;

and/or/not:

SQL> select last_name, job_id, department_id, salary from employees where job_id=‘SA_REP‘ or department_id=50 and salary>=8000;

SQL> select last_name, job_id, department_id, salary from employees where (job_id=‘SA_REP‘ or department_id=50) and salary>=8000;

排序:

SQL> select last_name, salary from employees order by salary;      列名 默认升序

SQL> select last_name, salary from employees order by salary desc; 降序

SQL> select last_name, salary from employees order by last_name; 字符串左对齐对比ascii码

SQL> select last_name, hire_date from employees order by hire_date; 日期按时间轴排序

SQL> select last_name, salary, commission_pct from employees order by salary desc, commission_pct desc;

SQL> select last_name, salary*12*(1+commission_pct) from employees order by 2;列参数

SQL> select last_name, salary*12*(1+commission_pct) total_salary from employees order by total_salary;起别名

时间: 2024-10-24 12:35:20

where和order by的相关文章

sql 大数据查询慎用 order by

今天在sql 查询中一个表中查询花了至少20秒时间,数据为620000行,sql语句如下: 测试一:使用order by  单单只是查询0,10行数据,耗时27.888s select a.id,a.county_id,a.county_name,a.town_id,a.town_name,a.village_id,a.village_name,b.province as province_name,b.name as city_name from place a left join city

优化order by 语句

mysql 中排序方式 有序索引顺序扫描直接返回有序数据 explain select customer_id from customer order by store_id\G; 这种方式在使用explain分析查询的时候显示为Using Index,不需要额外的排序,效率较高. Filesort排序 所有不是通过索引直接返回排序结果的排序都叫Filesort排序 explain select * from customer order by store_id\G; 这种方式在使用explai

sql篇 select from where group by having order by

以前,自己总是记不住如何用group by,如何用order by,什么时候用group by,什么时候用order by,什么时候两者一起用,怎么用,谁先谁后,现在,我们就一起来说一下Select   from   where   groupby   having   order by 的那些事,简单的总结一下,加深一下自己的印象,也给有需要的人提供点资源 Select   from   where   groupby   having   order by ,不用说,select from肯

Java [Leetcode 107]Binary Tree Level Order Traversal II

题目描述: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree {3,9,20,#,#,15,7}, 3 / 9 20 / 15 7 return its bottom-up level order

[LeetCode]Binary Tree Level Order Traversal II

Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example:Given binary tree {3,9,20,#,#,15,7}, 3 / 9 20 / 15 7 re

【leetcode SQL】Customers Who Never Order

Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything. Table: Customers. +----+-------+ | Id | Name | +----+-------+ | 1 | Joe | | 2 | Henry | | 3 | Sam

Apache的Order Allow,Deny 详解

Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权.所以,最常用的是:Order Deny,AllowAllow from All 注意“Deny,Allow”中间只有一个逗号,也只能有一个逗号,有空格都会出错:单词的大小写不限.上面设定的含义是先设定“先检查禁止设定,没有禁止的全部允许”,而第二句没有Deny,也就是没有禁止访问的设定,直接就是允许所有访问了.这个主要是用

UVALive 6467 Strahler Order 拓扑排序

这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ 以后能用CIN还是CIN吧 QAQ 贴代码了: 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 #include <iostre

Binary Tree Zigzag Level Order Traversal

原题: 题目解析:这个问题的实质是要我们按成访问二叉树的结点,并返回每层访问的结果,这里要求走Z字,其实就是一行正向一行反向. /* the kernel idea is visit a binary search tree in level and the additional work we have to label the end of one level. */ vector<vector<int> > zigzagLevelOrder(TreeNode *root) {

【LeetCode-面试算法经典-Java实现】【107-Binary Tree Level Order Traversal II(二叉树层序遍历II)】

[107-Binary Tree Level Order Traversal II(二叉树层序遍历II)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example