考虑表SAMPLE:
id integer
name nvarchar(10)
Run Code Online (Sandbox Code Playgroud)
有一个存储过程称为myproc.它只需要一个参数(即id)
给定一个名称作为参数,找到所有行name = @nameparameter并将所有这些ID传递给myproc
例如:
sample->
1 mark
2 mark
3 stu
41 mark
Run Code Online (Sandbox Code Playgroud)
当mark通过后,1 ,2 and 41将被传递到myproc个别.
即应发生以下情况:
execute myproc 1
execute myproc 2
execute myproc 41
Run Code Online (Sandbox Code Playgroud)
我无法触摸myproc也看不到它的内容.我只需将值传递给它.
我在接受采访时被问到这个问题.问题是我会得到一个堆栈,必须在堆栈的中间位置找到元素."top"索引不可用(这样你就不会pop()top/2次并返回答案).假设当pop()返回-1时你将到达堆栈的底部.不要使用任何其他数据结构.
例如:
stack index
-----
2 nth element
3
99
.
1 n/2 th element
.
-1 bottom of the stack(0th index)
Run Code Online (Sandbox Code Playgroud)
答案:1(我的意思不是中位数.找到中间位置的元素)
递归是唯一的方法吗?
谢谢,
PSY
我有以下表格:
Actual Optional
------ --------
4 3
13 6
20 7
26 14
19
21
27
28
Run Code Online (Sandbox Code Playgroud)
我要做的是选择:
1)"实际"表中的所有值.
2)如果它们形成具有"实际"表值的连续系列,则从"可选"表中选择值
预期的结果是:
Answer
------
4
13
20
26
3 --because it is consecutive to 4 (i.e 3=4-1)
14 --14=13+1
19 --19=20-1
21 --21=20+1
27 --27=26+1
28 --this is the important case.28 is not consecutive to 26 but 27
--is consecutive to 26 and 26,27,28 together form a series.
Run Code Online (Sandbox Code Playgroud)
我使用递归cte编写了一个查询但是它永远循环并且在递归达到100级后失败.我遇到的问题是27场比赛26场比赛,27场比赛27场比赛27场比赛27场比赛28场比赛27场比赛......(永远)
这是我写的查询:
with recurcte as
(
select num as one,num as two from …Run Code Online (Sandbox Code Playgroud) sql sql-server recursive-query common-table-expression sql-server-2008
我正在开发一个JAVA应用程序,用户在文本框中输入一个单词,该单词的同义词必须自动提供给他.
有一个词,是否有可能在JAVA中找到它的同义词及其根?我应该使用字典吗?
例如:
word: killer
synonym: murderer butcher hitman
word: killing
root: kill
Run Code Online (Sandbox Code Playgroud) 假设我有两张桌子,
Student Test
Id Name TestId Type StudentId
-- ---- ------ ---- ---------
1 Mark 774 Hard 1
2 Sam 774 Hard 2
3 John 775 Easy 3
Run Code Online (Sandbox Code Playgroud)
现在我必须找到那些在MySql中进行"硬"测试的学生(学生ID,姓名和证词).
哪一个更好(在性能方面)?
1.Select student.id,student.name,test.testid
from student
join test
on test.studentid=student.id and test.type='hard'
2.Select student.id,student.name,test.testid
from student
join test
on test.studentid=student.id
where test.type='hard'
Run Code Online (Sandbox Code Playgroud)
我可以知道原因吗?(假设有数百万学生和百万种类型的考试)
我用javascript写了一个蛇程序..问题是蛇的长度不超过2块....
<html>
<head>
<script type="text/javascript">
var matrix, body, dir, key, lastx, lasty, start, applex, appley, eat, hal;
function node(x, y) {
this.x = x;
this.y = y;
}
function draw() {
var str;
for (var i = 0; i < body.length; i++) {
matrix[body[i].x * 50 + body[i].y].bgColor = "black";
}
}
function halt() {
hal = 1 - hal;
if (hal == 0) automove();
}
function check_status() {
if (start == 1 && hal == 0) {
var ch; …Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌自定义搜索引擎并以JSON格式获取结果.对于某些查询,JSON结果具有重复键,因此它产生一个JSONException:重复键"昵称"等.
我正在使用JAVA.
String str=//contains the query result in json format
JSONObject ob=new JSONObject(str) produces the exception
Run Code Online (Sandbox Code Playgroud)
可能知道如何解决这个异常?
这是JSON的回复:
{
"kind": "customsearch#result",
"title": "The World Factbook: India - CIA - The World Factbook",
"htmlTitle": "The World Factbook: \u003cb\u003eIndia\u003c/b\u003e -",
"link": "https://www.cia.gov/library/publications/the-world-factbook/geos/in.html",
"displayLink": "www.cia.gov",
"snippet": "Jan 20, 2011 ... Features a map and brief descriptions of geography",
"htmlSnippet": "Jan 20, 2011 \u003",
"cacheid": "0n2U45w_dvkJ",
"pagemap": {
"metatags": [
{
"il.secur.classif": "UNCLASSIFIED",
"il.title": "(U) CIA The World Factbook",
"il.summary": "CIA - The World …Run Code Online (Sandbox Code Playgroud) 我有下表
Log
Date date
Description varchar
ID integer
Run Code Online (Sandbox Code Playgroud)
给定日期作为参数,我必须找到否.或者每天从开始日期到使用递归cte后的一个月记录的日志数. 有些天可能没有任何日志,所以我必须将计数打印为0.
例如:
select * from Log
Run Code Online (Sandbox Code Playgroud)
回报
1 insert 2011-01-17
2 blah blah 2011-01-23
3 blah 2011-07-07
Run Code Online (Sandbox Code Playgroud)
对于2011-01-17作为输入,输出应该是
2011-01-17 1
2011-01-18 0
2011-01-19 0
....
2011-01-23 1
.....
2011-02-17 0
Run Code Online (Sandbox Code Playgroud)
我必须使用递归 cte来做那个.我不知道如何在每次递归中将日期递增1以及如何停止\终止递归.
这是我到目前为止所做的事情:
with cte as (
select '2011-01-17' as dat,count(*) as count
from log group by date
having date='2011-01-17'
union all
select dateadd(day,1,dat) as dat,count(*) as count
from log,cte
group by date
having date=dateadd(day,1,dat)
where dat<'2011-02-17' …Run Code Online (Sandbox Code Playgroud) sql t-sql common-table-expression sql-server-2008 recursive-cte
sql ×4
java ×2
algorithm ×1
c ×1
dictionary ×1
javascript ×1
json ×1
mysql ×1
recursion ×1
sql-server ×1
synonym ×1
t-sql ×1