我为这个SQLFIDDLE创建了一个示例小提琴
CREATE TABLE [dbo].[Users](
[userId] [int] ,
[userName] [varchar](50) ,
[managerId] [int] ,
)
INSERT INTO dbo.Users
([userId], [userName], [managerId])
VALUES
(1,'Darry',NULL),
(2,'Cono',1),
(3,'Abros',2),
(4,'Natesh',1),
(5,'Ani',3),
(6,'Raju',5),
(7,'Pinky',5),
(8,'Miya',4)
Run Code Online (Sandbox Code Playgroud)
我的要求就是在特定经理下方显示所有员工层级
这是我试过的
WITH UserCTE AS (
SELECT userId, userName, managerId, 0 AS EmpLevel
FROM Users where managerId IS NULL
UNION ALL
SELECT usr.userId, usr.userName, usr.managerId, mgr.[EmpLevel]+1
FROM Users AS usr
INNER JOIN UserCTE AS mgr
ON usr.managerId = mgr.userId where usr.managerId IS NOT NULL
)
SELECT *
FROM UserCTE …Run Code Online (Sandbox Code Playgroud) 说,我在表中有100列.我不知道特定值可能存在于哪些列中.所以,我想检查所有列,如果它存在于任何100列中,我想选择它.
我搜索了一下,在大多数地方,解决方案似乎如下所示
select *
from tablename
where col1='myval'
or col2='myval'
or col3='myval'
or .. or col100='myval'
Run Code Online (Sandbox Code Playgroud)
我也读了一些论坛,据说这是一个不好的数据库设计案例,我同意,但我正在研究数据库中已有的表.
有更聪明的方法吗?
这个查询有什么问题:我收到了以下错误
SQL错误:ORA-00905:缺少关键字00905. 00000 - "缺少关键字"
它在第4行说错误.请指教
CREATE TABLE ORDERS
(
ID INT NOT NULL,
ord_date DATE,
AMOUNT double,
CUSTOMER_ID INT references CUSTOMERS(ID),
PRIMARY KEY (ID)
);
Run Code Online (Sandbox Code Playgroud) 在SQL Server中进行选择时,我可以在查询文本的开头或结尾添加%以表示我想要其他文本的任意数量的字符,但我不知道如何在中间执行此操作.
我想要SQL如下,
select *
From Table
Where name like '%[Error] Something failed in (%) session%'
Run Code Online (Sandbox Code Playgroud)
这与下面的数据运行时
Row | Date | Log Message
1 |2016-01-01 |'[Error] Something failed in (Freds) session'
2 |2016-01-01 |'[Error] Something failed in (Ilenes) session'
3 |2016-01-01 |'[Error] Something failed in (Freds) session'; Some other warning
4 |2016-01-01 |'[Warning] Something else went wrong'
5 |2016-01-01 |'[Warning] Some other warning'
Run Code Online (Sandbox Code Playgroud)
会给我的
Row |Date | Log Message
1 |2016-01-01 |'[Error] Something failed in (Freds) session'
2 |2016-01-01 |'[Error] …Run Code Online (Sandbox Code Playgroud) 最近我遇到了一个场景,ISNULL如果第一个字符串为null ,函数将返回截断的数据.
ISNULL(a, b);
Run Code Online (Sandbox Code Playgroud)
我发现a是5个字符,b是10个字符,但是当a为null时,它只返回5个字符b而不是全长.
这是一个已知的问题?
我试图用来REGEXP_REPLACE删除的所有标点符号varchar。我正在使用以下内容:
regexp_replace(d.NAME, [.,\/#!$%\^&\*;:{}=\-_`~()])
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误,说:
陈述1无效。错误:“或”附近的语法错误。
如何解决此问题以删除所有标点符号?
我想要每三行生成一个数字
CREATE TABLE #test(period INT)
INSERT INTO #test
VALUES (602),(603),(604),(605),(606),(607),(608),(609)
Run Code Online (Sandbox Code Playgroud)
我知道我们可以使用row_number窗口函数或while循环或生成序列cursor
SELECT period,
( Row_number()OVER(ORDER BY period) - 1 ) / 3 + 1
FROM #test
Run Code Online (Sandbox Code Playgroud)
结果;
+--------+-----+
| period | seq |
+--------+-----+
| 602 | 1 |
| 603 | 1 |
| 604 | 1 |
| 605 | 2 |
| 606 | 2 |
| 607 | 2 |
| 608 | 3 |
| 609 | 3 |
+--------+-----+ …Run Code Online (Sandbox Code Playgroud) 我有下表,我想根据业务范围仅选择上个月.
这些原始表:
fk_month fk_business_area
201706 8
201707 25
201707 27
201707 9
201707 8
201707 28
201707 26
201708 9
Run Code Online (Sandbox Code Playgroud)
选择后,我想要这个结果:
fk_month fk_business_area
201707 25
201707 27
201707 8
201707 28
201707 26
201708 9
Run Code Online (Sandbox Code Playgroud)
问候.
请考虑以下设置
create table #test([user] varchar(10))
insert into #test([user]) values ('test')
Run Code Online (Sandbox Code Playgroud)
当user列用方括号括起来时,查询返回结果,否则即使有匹配的记录也不会返回结果
SELECT *
FROM #test WHERE [user] = 'test' -- returns record
SELECT *
FROM #test WHERE user = 'test' --did not return record
Run Code Online (Sandbox Code Playgroud)
这引出了以下两个问题
where子句中使用而不转义它?我正在使用TransferManager将 blob 从一个容器复制到另一个容器。
CloudStorageAccount sourceStorageAccount = CloudStorageAccount.Parse(@"source storage account connection string");
CloudStorageAccount destStorageAccount = CloudStorageAccount.Parse(@"destination storage account connection string");
CloudBlobClient sourceBlobClient = sourceStorageAccount.CreateCloudBlobClient();
CloudBlobClient destBlobClient = destStorageAccount.CreateCloudBlobClient();
var sourceContainer = sourceBlobClient.GetContainerReference("sourceContainer");
var destContainer = destBlobClient.GetContainerReference("destContainer");
CloudBlockBlob sourceBlob = sourceContainer.GetBlockBlobReference("copy.txt");
CloudBlockBlob targetBlob = destContainer.GetBlockBlobReference("copy.txt");
TransferManager.CopyAsync(sourceBlob, targetBlob, true).Wait();
Run Code Online (Sandbox Code Playgroud)
但是当文件存在于目的地时,它会抛出错误说明
"跳过文件\" https://sourceabcd.blob.core.windows.net/sourcecontainer/test1.txt \" 因为目标\" https://sourceabcd.blob.core.windows.net/destcontainer/test1.txt \ “已经存在。”} System.Exception {Microsoft.WindowsAzure.Storage.DataMovement.TransferSkippedException
如果目标中存在文件,是否有覆盖文件的选项?