UNION 指令的目的是将两个 SQL 语句的结果合并起来。从这个角度来看, UNION 跟 JOIN有些许类似,因为这两个指令都可以由多个表格中撷取资料。 UNION 的一个限制是两个
SQL 语句所产生的栏位需要是同样的资料种类。另外,当我们用 UNION 这个指令时,我们只会看到不同的资料值 (类似 SELECT DISTINCT)。
UNION 的语法如下:
[SQL 语句...
分类:
数据库 时间:
2014-12-15 19:10:15
阅读次数:
147
一道非常有意思的题目。
原题如下:
Given a set of distinct integers, S, return all possible subsets.
Note:
Elements in a subset must be in non-descending order.
The solution set must not contain duplicate subsets.
For example,
If S = [1,2,3], a solution is:
[
[3],
[...
分类:
其他好文 时间:
2014-12-15 19:10:08
阅读次数:
123
SELECT 指令让我们能够读取表格中一个或数个栏位的所有资料。这将把所有的资料都抓出,无论资料值有无重复。在资料处理中,我们会经常碰到需要找出表格内的不同资料值的情况。换句话说,我们需要知道这个表格/栏位内有哪些不同的值,而每个值出现的次数并不重要。这要如何达成呢?在 SQL 中,这是很容易做到的。我们只要在 SELECT 后加上一个 DISTINCT 就可以了。DISTINCT 的语法如下:
...
分类:
数据库 时间:
2014-12-15 17:24:16
阅读次数:
221
分离、附加、备份、还原--去重select distinct 列名from表名--更新update fenshu set name = ‘李四’where code = 9--更改表名sp_rename 表名drop database 数据库名(删除数据库)drop table 表名Delete f...
分类:
数据库 时间:
2014-12-15 16:45:26
阅读次数:
243
select DISTINCT human.tid,log_pv_change.systafftid from human left join human_user on human.tid=human_user.hid left join human_house on human.tid = hu...
分类:
其他好文 时间:
2014-12-15 10:14:40
阅读次数:
176
题意:
Follow up for N-Queens problem.
Now, instead outputting board configurations, return the total number of distinct solutions....
分类:
其他好文 时间:
2014-12-15 00:14:20
阅读次数:
252
当数据量非常大,在同一个query中计算多个不相关列的distinct时,往往很容易出现数据倾斜现象,导致运行半天都不能得到结果。比如以下的SQL语句:select distinct(a), distinct(b), distinct(c) from tableName;a, b, c没有相关性。改...
分类:
其他好文 时间:
2014-12-14 10:35:42
阅读次数:
167
项目中要对数据按时间处理,在数据库中,时间处理的格式如2014-12-09 06:30:17时间查询出来如下所示:现在要查询具体有哪天的数据,应用substring函数,SQL如下:select distinct substring(( start_time ) from 1 for 10) as ...
分类:
数据库 时间:
2014-12-13 13:25:42
阅读次数:
222
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which...
分类:
其他好文 时间:
2014-12-13 06:07:09
阅读次数:
137
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.其实比N-Queens更简单,免...
分类:
其他好文 时间:
2014-12-12 11:38:54
阅读次数:
209