由买买提看人间百态

topics

全部话题 - 话题: col2
1 2 3 下页 末页 (共3页)
v*****r
发帖数: 1119
1
来自主题: Database版 - tbl1.col1 = tbl2.col2 (+)
Oracle's traditional non-ANSI standard left outer join query, your query is
equivalent to the following two queries if using ANSI stardard:
1. select tbl1.xx, tbl2.xx
from tbl1 LEFT OUTER JOIN tbl2
on tbl1.col1=tbl2.col2;
or
2. select tbl1.xx, tbl2.xx
from tbl2 RIGHT OUTER JOIN tbl1
on tbl2.col2=tbl1.col1;
t*********i
发帖数: 217
2
来自主题: Database版 - tbl1.col1 = tbl2.col2 (+)
Any one knows what this means?
select tbl1.xx, tbl2.xx from tbl1, tbl2 where tbl1.col1=tbl2.col2 (+)
many thanks!
B*****g
发帖数: 34098
3
来自主题: Database版 - 问个简单的sql语句
Oracle will fire the trigger, usually need to add WHEN clause to the trigger
.
I do know much about mysql.
how about
update xxxtable set col2 = col2||''
update xxxtable set col2 = col2, col3=col3
update xxxtable set col2 = col2, col3=col2
update xxxtable set col2 = CASE WHEN 1=1 THEN col2 ELSE col3 END
b****1
发帖数: 242
4
来自主题: Programming版 - 急:问一个SQL的题目
SELECT aaa.year,
MAX(CASE WHEN aaa.col2= 'WRA0020' THEN aaa.col3 ELSE NULL END),
MAX(CASE WHEN aaa.col2= 'OO0036' THEN aaa.col3 ELSE NULL END),
MAX(CASE WHEN aaa.col2= 'WRA0019' THEN aaa.col3 ELSE NULL END),
MAX(CASE WHEN aaa.col2= 'OO0033' THEN aaa.col3 ELSE NULL END),
FROM
(
SELECT * FROM a
WHERE col1 = ('DE00000009') AND (col2 = 'WRA0020' or col2 = 'OO0036' or col2
= 'WRA0019' or col2 = 'OO0033')
) aaa
GROUP BY aaa.year
B*****g
发帖数: 34098
5
来自主题: Database版 - 问个简单的sql语句
一般来说大家就是写
update tabA set col2 = CASE when conditionA then 'AAA' else col2 end
但是要求是当非conditionA时不update,上面这个只实现了非conditionA时col2值不变。
假如说col2上有trigger当update时,把tabA的record复制到tabB中,不update col2就
不会复制,而update col2=col2就会复制。
B*****g
发帖数: 34098
6
来自主题: Database版 - 问个简单的sql语句
it seems you still not get waht we are talking about. I believe I have post
the code for you.
***********************************************************
发信人: Beijing (中国万岁,北京加油), 信区: Database
标 题: Re: 问个简单的sql语句
发信站: BBS 未名空间站 (Thu Jan 27 20:29:15 2011, 美东)
一般来说大家就是写
update tabA set col2 = CASE when conditionA then 'AAA' else col2 end
但是要求是当非conditionA时不update,上面这个只实现了非conditionA时col2值不变。
假如说col2上有trigger当update时,把tabA的record复制到tabB中,不update col2就
不会复制,而update col2=col2就会复制。
******************... 阅读全帖
l******9
发帖数: 579
7
I am sorting two tables on SQL.
The two tables have the same column names and types and rows numbers.
I used order by to do sorting but the two tables are different in order.
Example,
col1 INT
col2 INT
col3 INT
col4 DOUBLE PRECISION
SELECT *
FROM table1 AS t1
ORDER BY t1.col1 , t1.col2, t1.col3, t1.col4 ASC
SELECT *
FROM table2 AS t2
ORDER BY t2.col1 , t2.col2, t2.col3, t2.col4 ASC
Table1 is :
col1 col2 col3 col4
80 790 3498 18654.064361
81 589 3182 2138518.05404
80 ... 阅读全帖
l******9
发帖数: 579
8
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: sort two same tables SQL but different results
发信站: BBS 未名空间站 (Fri May 9 09:57:41 2014, 美东)
I am sorting two tables on SQL.
The two tables have the same column names and types and rows numbers.
I used order by to do sorting but the two tables are different in order.
Example,
SELECT *
FROM table1 AS t1
ORDER BY t1.col1 , t1.col2, t1.col3, t1.col4 ASC
SELECT *
FROM table2 AS t2
ORDER BY t2.col1 , t2.col2, t2.col3, t2.col4 ASC
T... 阅读全帖
w*r
发帖数: 2421
9
来自主题: Database版 - Teradata 的大拿呢
来讨论一下join index的用法,说说你们的经历,我先砸一块砖,V2R6.1的optimizer
有问题
我有一个commonly used join(为了简便,很多syntax 的细节错误就不管了),
Table A Inner Join B on
a.col1=b.col1 and a.col2=b.col2 and a.col3=b.col3
and a.start_date <= b.start_date and a.end_date >= b.end_date
Table A 和 B分别对这些join的col都有hash index.
我建立了一个A $ B 的JI
create A_B_JI as
select a.col1, b.col1, a.col2, b.col2 , a.col3, b.col3 a.started_date
a.rowid, b.rowid
from a join b
on a.col1=b.col1 and a.col2=b.col2 and a.col3=b.col3
and a.start_date <= b.start_date an
B*****g
发帖数: 34098
10
来自主题: Database版 - Remove duplicate from oracle table
seems (1=3) > 2 > 4, why? how can 1=3? 谁给说说?
Thanks
col0 is unique
DELETE FROM table_name A
WHERE A.col0> ANY (SELECT B.col0 FROM table_name B
WHERE A.col1 = B.col1 AND A.col2 = B.col2)
DELETE FROM table_name A
WHERE A.col0 > (SELECT MIN(B.col0) FROM table_name B
WHERE A.col1 = B.col1 AND A.col2 = B.col2)
DELETE FROM table_name A
WHERE EXSITS (SELECT 1 FROM table_name B
WHERE A.col1 = B.col1 AND A.col2 = B.col2 AND A.col0 > B.col0
)
DELETE FROM
B*****g
发帖数: 34098
11
来自主题: Database版 - 问个简单的sql语句
问题还是挺多的. 比如说
怎样区分col2=col2, col2=col2||'' 和 col2='AAA' (if col2 value is 'AAA').
如果update10行,一行变了,9行没变怎么办?
还要不要fire trigger?
....
完了,再下去tom kyte来都不够用了。
M*********e
发帖数: 190
12
来自主题: Database版 - 请教一个SQL Server的面试题
Don't know TSQL.
In Oracle, use rowid pseudocolumn.
思想就是先找到有discint col1的所有行(得到set 1)和有distict col2的所有行(得
到set 2)。取 set 1和 set 2中rowid相同的行.
不知道有没有漏洞。
#################
create table test(col1 varchar2(5), col2 varchar2(5));
insert into test values ('V1','B');
insert into test values ('V12','F');
insert into test values ('V3','F');
insert into test values ('V2','C');
insert into test values ('V2','D');
insert into test values ('V3','E');
#################
select * from test where rowid i... 阅读全帖
M*********e
发帖数: 190
13
来自主题: Database版 - 请教一个SQL Server的面试题
or use a cross join.
select * from test where (col1, col2) in
(
select * from
(
(select col1 from test where col1 not in
(select col1 from test group by col1 having count(*)>1 ))
cross join
(select col2 from test where col2 not in
(select col2 from test group by col2 having count(*)>1 ))
)
);
COL1 COL2
c*******r
发帖数: 3289
14
来自主题: Database版 - 朋友圈遍历问题
col1, col2两个column存放人名id, 要求给出任意一个人的id,找出所有和这个人有联
系的人,以及所有其他有联系的人。例如
col1 col2
---- ----
A B
A C
B J
M B
X J
C K
Q A
输入的人名是A, 需要返回
1. COL2 WHERE COL1 = A,输出B和C;
2. COL1 WHERE COL2 = A, 结果加入Q;
3. COL2 WHERE COL1 IN (B,C,Q), 加入结果;
4. COL1 WHERE COL2 IN (B,C,Q),加入结果;
...
如此类推直至找不到新的ID
这似乎是个递归问题,能写个store procedure吗
l******9
发帖数: 579
15
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: sort two same tables SQL but different results
发信站: BBS 未名空间站 (Fri May 9 09:57:41 2014, 美东)
I am sorting two tables on SQL.
The two tables have the same column names and types and rows numbers.
I used order by to do sorting but the two tables are different in order.
Example,
SELECT *
FROM table1 AS t1
ORDER BY t1.col1 , t1.col2, t1.col3, t1.col4 ASC
SELECT *
FROM table2 AS t2
ORDER BY t2.col1 , t2.col2, t2.col3, t2.col4 ASC
T... 阅读全帖
n****t
发帖数: 182
16
来自主题: Statistics版 - 给duplicate加flag
Why not use data step?
proc sql;
select col1, col2, count(*) as count, 'N' as dup from a group by col1,
col2 having count=1

union select distinct col1, col2, count(*) as count, '
N' as dup from a group by col1, col2 having count>1
union select col1, col2, count(*) as count, 'Y'
as dup from a group by col1, col2 having count>1;
l******9
发帖数: 579
17
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: sort two same tables SQL but different results
发信站: BBS 未名空间站 (Fri May 9 09:57:41 2014, 美东)
I am sorting two tables on SQL.
The two tables have the same column names and types and rows numbers.
I used order by to do sorting but the two tables are different in order.
Example,
SELECT *
FROM table1 AS t1
ORDER BY t1.col1 , t1.col2, t1.col3, t1.col4 ASC
SELECT *
FROM table2 AS t2
ORDER BY t2.col1 , t2.col2, t2.col3, t2.col4 ASC
T... 阅读全帖
a*********u
发帖数: 1463
18
来自主题: Database版 - 问个sql/ ssis的问题 谢谢!
有两个sql server table
table1 (col1, col2, col3 ... col9)
table2 (cola, colb, colc)
目的是弄一个 excel table3
包含col1, col2, col3, col5, col6, colc
colc的值是当tbl1.col1=tbl2.cola and tbl1.col2 = tbl2.colb
我现在的想法是
select col1,col2,col3, col5, col6, 0 as colc from tbl1 into temp_tbl1
update temp_tbl1
set temp_tbl1.colc = tbl2.colc
from temp_tbl1
inner join tbl2
on (temp_tbl1.col1 = tbl2.cola and temp_tbl1.col2 = tbl2.colb)
然后再用ssis 把数据弄到excel里
请问还有什么简单易操作的方法吗
谢谢
c*******e
发帖数: 8624
19
来自主题: Database版 - sql 请教
col1 = A, B这个column
col2 = 另外一个
select col1 ,
max(col2) ,
(sum(col2) - max(col2)) * 1.00 / max(col2)
from your_table
group by 1
order by 1 ;
j****s
发帖数: 881
20
来自主题: Database版 - 请教一个SQL Server的面试题
多谢上面几位解释,尤其是北京姐姐,把题目的意思讲清楚了。
另一种写法:
select col1, col2 from table
where clo1 not in
(select col1, count(col2) from table
group by clo1
having count(col2)>1
Intersect
select col1, col2 from table
select col2, count(col1) from table
group by clo2
having count(col1)>1)
记下IDs,发包子去了。
y*****g
发帖数: 677
21
来自主题: Database版 - How to split a column into several rows?
My solution is only work for fixed number of values in the col2,
for simplicity, if there is only 2 values in col2,
the following works:
insert into combined select a.col1, substring_index(a.col2,',',1) from
mytest a union all select b.col1,substring_index(b.col2,',',-1) from mytest
b;
mysql> select * from newt order by col1;
+------+-------------------------------+
| col1 | substring_index(a.col2,',',1) |
+------+-------------------------------+
| a1 | b11 |
| a1 ... 阅读全帖
x**l
发帖数: 369
22
来自主题: Programming版 - 急:问一个SQL的题目
SQL新手,做PROJECT碰到这样一个问题:
用户给的一个SQL语句
SELECT * FROM a
WHERE col1 = ('DE00000009')
AND (col2 = 'WRA0020' or col2 = 'OO0036' or col2 = 'WRA0019' or col2 = '
OO0033')
返回下列结果:
year col2 col3
2009 OO0033 3440.0000
2009 OO0036 330.0000
2009 WRA0019 259.9360
2009 WRA0020 1756.3800
2010 OO0033 3750.0000
2010 OO0036 375.0000
2010 WRA0019 282.4740
2010 WRA0020 2048.8700
2011 OO0033 4210.0000
2011 OO0036 285.2200
2011 WRA0019 789.3160
20... 阅读全帖
d**e
发帖数: 6098
23
In oracle, say select max,
col1 col2 col3
--------------------
a b 1
a b 2
c d 4
c d
-------------------
group by col1, col2, i want something like a/b will return 2, c/d return
null, since c/d has a null value.
"select col1, col2, max(col3) from table group by col1, col2" doesn't work.
Is ia any way to make the max function return null if there is a null value
in the column?
Thanks!
c*****d
发帖数: 6045
24
来自主题: Database版 - 这个sql语句怎么写
select a.col1, a.col2, b.col3
from a,b
where a.col1 = b.col1
and a.col2 = a1
union all
select a.col1, a.col2, c.col5
from a,c
where a.col1 = c.col1
and a.col2 <> a1
i*****w
发帖数: 75
25
建议一种方法:
1) UNPIVOT TableA, You will get:
ID1, COL1, CONTENT1
ID2, COL2, CONTENT2
ID3, COL3, CONTENT3
2) Join TableA and TableB by LIKE.
EXAMPLE:
-- Prepare Source Table
DECLARE @tblA Table (ID int identity, col1 varchar(100), col2 varchar(100),
col3 varchar(100))
INSERT INTO @tblA (col1, col2, col3)
SELECT 'this is a test', 'I am not sure', 'Give it a try.'
UNION ALL
SELECT 'who cares', 'No one knows', 'Why not'
UNION ALL
SELECT 'it is impossible', 'please let me know', 'be honest'
-- ... 阅读全帖
s**********o
发帖数: 14359
26
来自主题: Database版 - 请教一个sql问题
你的TABLE1的各个COLUMN NAME是什么呢,我觉得TABLE1本身就有问题
TABLE 1,如果是这样一个TABLE,本身就没有意义
ID COL1 COL2 COL3
1 小甲 老乙 大丙
2 小A 老B 大C
3 张三 李四 王二麻子
显然,虽然叫COL1, COL2. COL3,但肯定是有些联系,其实是这样的
COL1=学生
COL2=老师
COL3=家长
其实TABLE1应该是这样
ID 学生 老师 家长
1 小甲 老乙 大丙
2 小A 老B 大C
3 张三 李四 王二麻子
如果TABLE1建好的话,TABLE2和TABLE3都没什么意义,如果你是CLEANUP
直接SELECT COL1 AS ID1, COL2 AS ID2, COL3AS ID3 FROM TABLE1
因为是DDL,你的COLUMN数肯定是一定的,不可能是N个,只能一一列举
不过合并后的TABLE3还是没什么意义,因为ID1 ID2本身... 阅读全帖
w****w
发帖数: 521
27
来自主题: Database版 - 朋友圈遍历问题
Something like:
with friend_cte as (
select col1 as col from friend where col2='a'
union
select col2 as col from friend where col1='a'
union
select col1 as col from friend join friend_cte
on friend.col2=friend_cte.col
union
select col2 as col from friend join friend_cte
on friend.col1=friend_cte.col
);
select col from friend_cte;
c**t
发帖数: 2744
28
来自主题: DotNet版 - nHibernate mapping question
Can any nHibernate expert let me know what's wrong with the following? I
alwasy got Acccount.ListAttr as null; when do "foreach(var a in Account.
ListAttr)" I got invalid cast error: can't cast ISet to IList..
I have Account.hbm.xml as follows:
...




..
and Account.cs has:
public virtual ISet ListAttr {get; set; }
..
Also have SomeOtherClass.hbm.xml:
...
阅读全帖
c*********e
发帖数: 16335
29
来自主题: Programming版 - 请教思路 数据同步有关
(select col1,col2,col3 from table1
except
select col1,col2,col3 from table2)
union
(select col1,col2,col3 from table2
except
select col1,col2,col3 from table1)
v*****r
发帖数: 1119
30
来自主题: Database版 - 请教一个SQL Server的面试题
嗯,很好,就有点 double-negative,俺加一个茴的写法 (natual join):
select t1.*
from (select * from test where col1 in (select col1 from test group by
col1 having count(*)=1)) t1,
(select * from test where col2 in (select col2 from test group by
col2 having count(*)=1)) t2
where t1.col1 = t2.col1
B*****g
发帖数: 34098
31
来自主题: Database版 - 请教一个SQL Server的面试题
有包子,上partition by solution
SELECT col1, col2
FROM
(SELECT col1,
col2,
COUNT(1) OVER(PARTITION BY col1) AS 'col1count',
COUNT(1) OVER(PARTITION BY col2) AS 'col2count'
FROM table) t
WHERE t.col1count = 1 and t.col2count = 1


98.248.]
B*****g
发帖数: 34098
32
叫你朋友参加CINAOUG 9月7号的活动
table1(id, col1)
table2(id, col2)
SELECT id, col1, null AS col2
from table1
union all
SELECT ID, null, col2
from table2
e*********y
发帖数: 29
33
来自主题: Database版 - 高手请进
table A
Id,col1,col2,col3
1 a b c
2 c e f
3 a b c
4 a b c
table B
col1,col2,col3,Id
aa bb cc 1
cc bb dd 1
ee ff gg 1
ff aa ee 2
aa bb cc 2
bb ee ff 4
cc bb dd 4
ee ff gg 3
table c:
col1,col1,col2,col3, count
1 aa bb cc 2
2 cc bb dd 2
3 ee ff gg 2
4 ff aa ee 1
5 bb ee ff 1
现在有table A, table B, 和 table c
有没有办法不用每次run Inquery,而直接得到table c 的结果.
就是说table C的结... 阅读全帖
s***s
发帖数: 1301
34
我有两个个表Table A 有3个column Col1, Col2, Col3,和Keyword Table B it has
keyword1, keyword2, keyword3.....
我想查Table A 中有哪些record, 其任何一个column (Col1, or Col2, or Col3) 有
任何一个Table B 中keyword 。
我想到的方法是:
利用cursor 来获取一个一个keyword, 然后传到@p1 下面的dynamic query来查取
select *
from A
where Col1 like '%@p1%' or Col2 like '%@p1%' or Col3 like '%@p1%'
问题是我的keyword table可能有上千个,这种方法就比较低效。
请问有什么比较好的方法来实现呢?
谢谢!
l******y
发帖数: 60
35
来自主题: Database版 - 请教一个SQL的问题
问个问题
我有如下table:
col1 col2 col3
A S 4
A T 12
A U 14
A V 6
A W 9
A X 17
A Y 23
A Z 346
B S 45
B T 34
B U 34
B V 56
B W 67
B X 342
B Y 23
B Z 1
C S 34
C T 78
C U 3
C V 8
C W 34
C X 6
C Y 7
C Z 100
对于col1 中的每个值,要找出col3值最小的一列。即如下结果:
col1 col2 col3
A S 4
B Z 1
C U 3
Table很大,每一个distinct col1 都有80万个col2与之对应,即: select count(*)
wher... 阅读全帖
i*****w
发帖数: 75
36
来自主题: Database版 - 请教一个SQL的问题
Method 1: Row_Number, Partition by
Method 2: Assume there are no duplicated records for each group so Col1 and
Col3 are unique:
Declare @tbl Table (col1 varchar(10), col2 varchar(10), col3 int)
INSERT INTO @tbl (col1, col2, col3)
SELECT 'A', 'S', 4 UNION ALL
SELECT 'A', 'T', 12 UNION ALL
SELECT 'A', 'U', 14 UNION ALL
SELECT 'A', 'V', 6 UNION ALL
SELECT 'A', 'W', 9 UNION ALL
SELECT 'A', 'X', 17 UNION ALL
SELECT 'A', 'Y', 23 UNION ALL
SELECT 'A', ... 阅读全帖
s*******n
发帖数: 4402
37
来自主题: Database版 - 请教一个SQL的问题
楼上几位都是高手,给出的解比较复杂,我给一个简单的:
先建一个#table, 原来的表是tb
create table #table (col1 char(1), col2 char(1), col3 int)
insert into #table(col1) (select distinct col1 from tb)
update #table set col3=c.min_col3
from #table as t
join (select min_col3=min(col3), col1 from tb
) as c on t.col1=c.col3
update #table set col2=t.col2
from #table as t join tb as b on t.col1=b.col1 and t.col3=b.col3
不管你原来数据有没有重复的,你就是要最小的那一行,这个可以达到要求。
o******6
发帖数: 538
38
来自主题: Statistics版 - [合集] 请教:SAS help
☆─────────────────────────────────────☆
cyear (cyear) 于 (Wed May 14 23:40:09 2008) 提到:
有个文件:
A 4
A 5
B 1
B 2
B 3
怎么能得到:
A 9
B 6
谢谢!!
☆─────────────────────────────────────☆
cyear (cyear) 于 (Wed May 14 23:59:31 2008) 提到:
哪位帮帮忙!1
☆─────────────────────────────────────☆
GunS (火枪) 于 (Thu May 15 08:24:25 2008) 提到:
proc sort data=a;
by col1;
run;
data b;
set a;
by col1;
if first.col1 then col3=0;
col3+col2;
if last.col1;
drop col2;
rename col3=col2;
run;

有个文件:
A 4
A 5
B
l******9
发帖数: 579
39
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: SQL copy a table into a new table and add a new column
发信站: BBS 未名空间站 (Fri May 23 12:05:22 2014, 美东)
need to copy a table into a new table on SQL server 2008. Also, add a new
column into the new table.
The values of the new column depends on the compare result between the new
table and another table.
Example,
Table1:
col1 col2 col3
abc 346 6546
hth 549 974
Table1_new:
col1 col2 col3 c... 阅读全帖
B*****g
发帖数: 34098
40
来自主题: Database版 - sql query help
SELECT col1, col2, col3, COUNT(1)
FROM tab1
GROUP BY ROLLUP(col1, (col2,col3))
B*****g
发帖数: 34098
41
来自主题: Database版 - 菜鸟问题,急
CREATE TABLE NewTable AS
SELECT *
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)
or
INSERT INTO NewTable
SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)
M***7
发帖数: 2420
42
来自主题: Database版 - 菜鸟问题,急
guys, thanks a lot .
Finally I used the following query
=====================
INSERT INTO NewTalbe
SELECT col1, col2 FROM TABLE1
UNION ALL
SELECT col3 col4 FROM TABLE2
======================
It woks.
If I use
=================
CREATE TABLE newtable AS
SELECT *
FROM (SELECT col1, col2 FROM TABLE1
UNION ALL
SELECT col3 col4 FROM TABLE2)
===================
It still did not work.
Could anyone explain it a little bit detail for me? I am really a rookie in
SQL.
Thanks.
M***7
发帖数: 2420
43
来自主题: Database版 - A rookie's query question
Hi all. I am a newbie with SQL. Here is my question:
The table is like
col1 col2 col3
a1 1 c
a1 2 a
...
a1 100 t
a2 1 d
a2 2 c
...
a2 100 g
a3 1 h
...
a3 100 d
now I am trying to make a function. The parameters are 2 ints of col2(such
as 2,81). I want to return a table containing the composition of that two
input parameters which is like
for parameter (2,81)
dt 10%
ac 40%
tt 50%
could anyone help me out?
m*****i
发帖数: 2325
44
来自主题: Database版 - 一个oracle performance 的问题。
oracle 9i。
我有一个大table 叫 TA 吧, 7,8 个million record 吧。
table 有primary key。 由好几个column 组成。就叫 (col1,col2,col3,col4,
col5,col6) 吧。
当我运行如下query 时,非常慢,要十几分钟。
1) select count(*) from TA a where a.col1=601
但当我运行下面的query 是 却非常快,十几秒就行了。
2) select count(*) from TA a where a.col1=601 and a.col2 like 'ABC%'
为什么呢? 有什么办法可以让 1) 也运行的快点吗?
c*****d
发帖数: 6045
45
来自主题: Database版 - 一个oracle performance 的问题。
单字段的primary key能保证该字段被index
对于复合PK,如果PK是(col1,col2),没问题,查询可以用Index
如果PK是(col2,col1),不行,查询不可以用该Index
c*****d
发帖数: 6045
46
来自主题: Database版 - 一个oracle performance 的问题。
好,更精确的说:
单字段的primary key能保证该字段被index,但是oracle未必一定使用该Index
对于复合PK,如果PK是(col1,col2),查询可以用Index,但是oracle未必一定使用该
Index
如果PK是(col2,col1),oracle查询不用该Index,除非你加入hint
这下大家满意了吧
i****a
发帖数: 36252
47
来自主题: Database版 - 问个简单的sql语句
I am always curious, is update xxxtable set col2 = col2 really an update.
curious on 2 levels. on the query execution level, is it really a
transaction, or does it set off trigger
on disk IO level, does it cause disk activity.

变。
n********6
发帖数: 1511
48
Environment: Win2003, SQL2005,
Process: Load .xls by using SSIS Wizard (DB->Task->Import Data)
.xls File Structure: (col1, col2, ..., col8, col9)
Columns: col8:numbers; col9: numbers
First Line: xx, xx,... xx, xx (to set col8, col9 character)
Loading result:col1, col2, ... col8 (nvarchar), col9(float)
Question: Why col8 nvarchar while col9 float?
Thank you.
p********l
发帖数: 279
49
来自主题: Database版 - 问一个sql查询语句的问题
You can try to use CTE and row_number:
WITH TableRN AS
(
SELECT ROW_NUMBER() OVER(ORDER BY col1) AS rownum,
col1,
col2
FROM Table1
)
SELECT rownum, col1, col2
FROM TableRN
WHERE rownum BETWEEN n1 AND n2
ORDER BY rownum;
T****U
发帖数: 3344
50
来自主题: Database版 - 请教几个面试题
My answer to Q3
select * from
((select col1, col2, col3, col4, col5 from sevencol)
minus fivecol)
Union
(fivecol minus
(select col1, col2, col3, col4, col5 from sevencol))

query
1 2 3 下页 末页 (共3页)