本人有简单问题求教
已通过查询获得若干个结果,现必须将这些结果insert
到另一个表,say: result(number,value1,value2)
现在问题是:
只有value1 和value2是已知道的(即前面的结果)。可是
number 是一个primary key,表示序号如1,2,3,4,5,....
请问怎么样写insert into result(number,value1,value2)..???
我的意思是有100个value1,value组成的tuple.如何得到
table result such as
number value1 value 2
1 x1 y1
2 x2 y2
.....................
100 x100 y100
我尝试用
insert into result(number,value1,value2)
(
select number,A.value1,A,value2
from A
)
但是如何累加num
其实就两个column的表,12 million也不算大。最后的表不小。一下update 48 个
column可能要写挺长时间。
你可以先把最后表的结构create出来,先写进去所有的unique id,create index。然
后每次update一个column。
create table t1( id int, value1 int);
create table t2( id int, value2 int);
create table t3( id int, value3 int);
insert into t1 values (2,2),(3,3);
insert into t2 values (1,1),(3,3);
insert into t3 values (1,1),(2,2);
select id into final from (select id from t1 union select id from t2 union
select id from t3) as t;
create clustered index id on final(id);
al... 阅读全帖
Here is my implementation in C++. Just my two cents.
// -------------------------------------------------------------------------
---
// Name: lowestCommonAncestor
// Description: Given two values representing two node's values in a
binary
// search tree, find the lowest common ancestor of the two nodes.
//
// Assumption: We assume those two values are different and both exist in
the
// tree if the tree is not empty.
//
// Node: This algorithm returns root node if one of ... 阅读全帖
CTE + 一串 left outer join 可以实现。
SQL Server 三个table:
create table t1( id int, value1 int);
create table t2( id int, value2 int);
create table t3( id int, value3 int);
insert into t1 values (2,2),(3,3);
insert into t2 values (1,1),(3,3);
insert into t3 values (1,1),(2,2);
with idtable as
(select id from (select id from t1 union select id from t2 union
select id from t3) as t)
select idtable.id,isnull(value1,-1) as value1, isnull(value2,-1) as value2,
isnull(value3,-1) as value3
from idtable left ou... 阅读全帖
贴一个我的recursive代码,time complexity是O(n^2),large Judge用了144ms,不
是最优解,但是容易理解
bool isScramble(string s1, string s2) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (s1 == s2)
return true;
int size = s1.size();
int value1=0, value2=0;
for (int i=0; i
value1 += (s1[i]-'a');
value2 += (s2[i]-'a');
}
if (value1 != value2)
r... 阅读全帖
In the result table, you may need an identity.
CREATE TABLE RESULT
(id int identity(1,1) not null,
value1 datatype,
value2 datatype
)
Then you can insert the values of value1 and value21.
INSERT INTO RESULT(value1, value2)
SELECT value1,value2
FROM A
Hope that it works.
写了一个,不过有点繁
data a;
input id $ week value1;
datalines;
a 1 12
a 2 22
a 3 33
a 4 .
a 5 .
a 6 .
a 7 .
b 1 78
b 2 .
b 3 .
b 4 .
b 5 .
b 6 .
b 7 .
b 8 .
c 1 88
c 2 67
c 3 76
c 4 .
c 5 .
c 6 .
;
data b;
set a;
by id;
if value1 ne . then do
value2=value1;
retain value2;
end;
if last.id then output;
keep id value2;
data a;
merge a b;
by id;
proc print data=a;run;
"Programming Interviews Exposed" has the solution. One of the properties
of BST is that left subtree nodes is always smaller than right subtree
nodes. So all you need to do is to iterate through the BST from the root
and find the first node that is lesser than one node and greater than
the other node. Pseudo code:
If valuel and value2 are less than the current node's value
Examine the left child
If valuel and value2 are greater than the current node's value
Examine the right child
Otherwise
The
【 以下文字转载自 Programming 讨论区 】
发信人: careerchange (Stupid), 信区: Programming
标 题: How to convert string to string array (or vector)
发信站: BBS 未名空间站 (Mon Sep 13 19:18:21 2010, 美东)
It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
what's the best data structure for storing and looking up a huge amount of
url's (presented in a prefix format) like these:
com.google.www -> value1
com.yahoo.finance -> value2
com.yahoo.finance/stocks -> value3
com.yahoo/finance -> value2
1.2.3.4/node/123 -> value4
....
the requirements are:
1. it has to be compact (compression if necessary).
2. lookup time should be fast (constant would be ideal, but a few level of
tree lookup is fine too).
Since the DP stores all the values, we don't need to handle (log v_N) times.
So, it is same time complexity of Knapsack problem.
new_V < 2*V
Knapsack can be handle in O(N*V), so this question can be handled in O(N*2*V
) = O(N*V). N is the type of coins.
the O(N*V) codes for knapsack are hard to read. following is sample codes,
time = O(V * sigma log s_i) .
public static int getMinStampNum(Coin[] coins, int V) {
ArrayList p = new ArrayList();
for (Coin coin ... 阅读全帖
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: keep group of values of SQL procedure in one table
发信站: BBS 未名空间站 (Sat May 24 09:48:08 2014, 美东)
I need to print out a group of values from a procedure on SQL server 2008.
If I use select , it generated a distinct table into the result part of SQL
server 2008 managemetn studio every time the procedure is called.
i need to call the procedure in a loop. I want to print the values into one
table.
Thx!
while
begin
my_proce... 阅读全帖
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to generate a value by combining value1 to value4, suppose that it is
called "value_combine". The "value_combine" should be unique. For example,
given the different combinations... 阅读全帖
要连接两个表,Key用来联接的。这两个表里,都有一些key missing,所以我想连接后
的数据显示null value from both tables. 谁知道怎么弄?
表一
Key Value1
A 1
B 2
C 2
D 2
表二
Key Value2
A 3
B 2
F 2
连接后的表:
Key Value1 Value2
A 1 3
B 2 2
C 2 null
D 2 null
F null 2
In Oracle, it is quite easy to achieve this by using SEQUENCE.
E.g.,
CREATE SEQUENCE my_sequence
INCREMENT BY 1
START WITH 1
NOMAXVALUE;
INSERT INTO result(number,value1,value2)
select my_sequence.nextval, A.value1,A,value2
from a;
DROP SEQUENCE my_sequence.
In DB2, you must use user-defined function with scratchpad (check
Chamberline's book for coding examples) to achieve the same effects.
I need to print out a group of values from a procedure on SQL server 2008.
If I use select , it generated a distinct table into the result part of SQL
server 2008 managemetn studio every time the procedure is called.
i need to call the procedure in a loop. I want to print the values into one
table.
Thx!
while
begin
my_procedure()
end
my_procedure()
# do something
select value1, value2, value3
i need to keep the
value1, value2, value3
in one single table after the loop is don... 阅读全帖
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: generate unique integer ID from columns in SQL table
发信站: BBS 未名空间站 (Fri Nov 14 17:36:46 2014, 美东)
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to g... 阅读全帖
Is there anything wrong with this C++ class declaration?
class temp
{
int value1;
mutable int value2;
public :
void fun(int val)
const{
((temp*) this)->value1 = 10;
value2 = 10;
}
};
为什么我编译没问题? 再有((temp*) this)什么意思? const函数不是不能改变
member
variable?
多谢
☆─────────────────────────────────────☆
igah (igah) 于 (Mon Sep 21 21:38:57 2009, 美东) 提到:
here is the problem i am facing a lot when writing many applications in c++.
let's say you have a user class Foo and you need some parameters, e.g.
struct Foo {
int value1;
double value2;
};
and the parameters are read from some property file of name-value pairs:
value1=123
value2=23.4
the parameters can be changed at run time through some user interface (e.g.
jmx like controls) which sets the values al
It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
etc......
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: generate unique integer ID from columns in SQL table
发信站: BBS 未名空间站 (Fri Nov 14 17:36:46 2014, 美东)
I need to generate a new column in a table in a sql database.
the given table is:
id1 value1 value2 value3 value4
9465 387 801 1990 20
All columns are integer. All columns are integer. value1 and value2 are
always 3 digits, value3 are year value, value4 is not more than 3 digits.
I need to g... 阅读全帖
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: keep group of values of SQL procedure in one table
发信站: BBS 未名空间站 (Sat May 24 09:48:08 2014, 美东)
I need to print out a group of values from a procedure on SQL server 2008.
If I use select , it generated a distinct table into the result part of SQL
server 2008 managemetn studio every time the procedure is called.
i need to call the procedure in a loop. I want to print the values into one
table.
Thx!
while
begin
my_proce... 阅读全帖
RT
if I have a dataset as below:
id week value1
a 1 12
a 2 22
a 3 33
a 4 .
a 5 .
a 6 .
a 7 .
b 1 78
b 2 .
b 3 .
b 4 .
b 5 .
b 6 .
b 7 .
b 8 .
c 1 88
c 2 67
c 3 76
c 4 .
c 5 .
c 6 .
I need to capture the last missing value1 for each ID as value2 to achieve
the following dataset:
id week value1 value2
a 1 12 33
a 2 22 33
a 3 33 33
a... 阅读全帖
there is a table with different variables as below,
yyyymmm, value1(%), value2(%), value3(%), .......
now I need to calculate every three observations' accummulated percent, i.e.
quarterly accummulated percent for value1,value2, value3,.....
How can I realize this? Thank you very much.
one is...
data select;
set original;
where var1 in (value1 value2 value3 value4 value5 value6 value7 value8)
or
var1 between minvalue and maxvalue or
var2 in (number1 number2 number3) or
var3 in (number1 number2 number3) or
var4 in (number1 number2 number3) or
var5 in (number1 number2 number3) or
var6 in (number1 number2 number3) or
var7 in (number1 number2 number3) or
var8 in (number1 number2 number3) or
... 阅读全帖
【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: keep group of values of SQL procedure in one table
发信站: BBS 未名空间站 (Sat May 24 09:48:08 2014, 美东)
I need to print out a group of values from a procedure on SQL server 2008.
If I use select , it generated a distinct table into the result part of SQL
server 2008 managemetn studio every time the procedure is called.
i need to call the procedure in a loop. I want to print the values into one
table.
Thx!
while
begin
my_proce... 阅读全帖
最近面了几个公司,大的如LG,中等的PDB,小的有20~30个人的三个,tiny的7,8个
人的两三个,人不错,但太risky。
最想去的没有中, 水平问题。从一个,凑活300K过日子。
拿到卡后的骑驴找马。太累,收山,生娃。
1. numPath from top left to bottom right.
写没想到这个居然栽了,被对方态度搞的不能focus,写出来但总出错。水平问题。
2. find median in 2 sorted arrays
3. find median in very large file of LONGs in many machines.
global value space binary search; bucket stats; reduce number of passes of
files.
4. implement web crawler in java
不是project,就是 task queue, executor。
5. implement Timer, Timer Task in java
prirotity queue; num... 阅读全帖
I need to so a sql query on IBM netezza sql database from Aginity workbench
on win7.
My query:
SELECT *
from table1 AS c ,
table2 AS b
where CAST(c.id as int) = b.id
in table1, id is character varying(20) and in table2, id is int.
Table1:
id value1 value2
'985' 'casdqwdc' '654.3184' // they are all char
Table2:
id value1
985 694381 // id is int, value1 is int
I got error:
ERROR [HY000] ERROR: pg_atoi: error in "id": can't parse "id"
Any help would be apprec... 阅读全帖
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: Error of SQL query on IBM netezza SQL database from Aginity workbench
发信站: BBS 未名空间站 (Fri Dec 5 16:46:56 2014, 美东)
I need to so a sql query on IBM netezza sql database from Aginity workbench
on win7.
My query:
SELECT *
from table1 AS c ,
table2 AS b
where CAST(c.id as int) = b.id
in table1, id is character varying(20) and in table2, id is int.
Table1:
id value1 value2
'985' 'casdqwdc' '654.3184' // t... 阅读全帖
What's the most efficient data structure in Java to express:
key -> {key1:value1, key2:value2, ... keyN:valueN}
HashMap is one way. Since I need no operation other than
getter/setter, class is kind of heavy. Anything lighter?