[SQL Server]收集SQL语句 - MS-SQL Server / 应用实例
上星期去新蛋面试时.面试题中有两道数据库的题目,现拿出来收集大家的实现方法
1.题一
数据库表结构:
SQL code:
Create table A
(
Id int not null,
[Name] nvarchar(40),
[Rank] int
)
表里面的值:
Id Name Rank
------------------------------
1 I 1
1 have 2
1 a 3
1 dream 4
2 Oh 1
查询结果是:
Id Name
----------------------------------
1 I have a dream
2 oh my god
2 my 2
2 god 3
2. 题二
有两个表(表A,表B)结构一样,但里面的值不一样,在表A中存在的记录可能在表B中不存在,要求写SQL语句查询出在表A中不在表B中的记录
我贴上我的查询语句.欢迎各位拍砖:
题一:
创建函数
SQL code:
CREATE FUNCTION JoinStr
(
@id int
)
RETURNS nvarchar(200)
AS
BEGIN
-- Declare the return variable here
DECLARE @s nvarchar(200)
-- Add the T-SQL statements to compute the return value here
SELECT @s=ISNULL(@s+' ','') + [key] from Test WHERE Id= @id
-- Return the result of the function
RETURN @s
END
SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://w
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
原SQL语句SQL code:
SELECT t6.FName '操作工',t1.FDate '日期',t5.FName '制单人',t3.FName '设备',t4.FName '班制',
t7.FBillNo '工艺指令单号',t8.FName '岗位',t2. ......