查询结果中的标识列 [英] Identity column in query result

查看:94
本文介绍了查询结果中的标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在触发如下查询:


SELECT TaskName,StartDate FROMTasks

WHERE StartDate> =''01 -Aug-2003''


现在结果如下:


TaskName StartDate

----------- ---------------

Task1 01-Aug-2003

Task5 10-Oct-2003

>



现在我想要的是:

Sl。 No. TaskName StartDate

----------------------------------

1 Task1 01-Aug-2003

2 Task5 10-Oct-2003

如何获得Sl。编号字段(表中不存在)。

可以这样做吗?


-surajit

I am firing a query like:

SELECT TaskName, StartDate FROMTasks
WHERE StartDate >= ''01-Aug-2003''

Now the result comes as:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003

etc.

Now what I want is this:
Sl. No. TaskName StartDate
----------------------------------
1 Task1 01-Aug-2003
2 Task5 10-Oct-2003
How do I get the Sl. No. field (it does not exist in the table).
Can I do it?

-surajit

推荐答案

" Surajit Laha" < S _ **** @ rediffmail.com>在消息中写道

新闻:ba ************************** @ posting.google.c om ...
"Surajit Laha" <s_****@rediffmail.com> wrote in message
news:ba**************************@posting.google.c om...
我正在触发如下查询:

SELECT TaskName,StartDate FROMTasks
WHERE StartDate> =''01 -Aug-2003''

现在结果如下:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003



现在我想要的是:

Sl。 No. TaskName StartDate
----------------------------------
1 Task1 01- 2003年8月
2 Task5 10-Oct-2003

如何获得Sl。编号字段(表中不存在)。
我可以这样做吗?

-surajit
I am firing a query like:

SELECT TaskName, StartDate FROMTasks
WHERE StartDate >= ''01-Aug-2003''

Now the result comes as:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003

etc.

Now what I want is this:
Sl. No. TaskName StartDate
----------------------------------
1 Task1 01-Aug-2003
2 Task5 10-Oct-2003
How do I get the Sl. No. field (it does not exist in the table).
Can I do it?

-surajit




SELECT T1 .StartDate,T1.TaskName,COUNT(*)AS Cnt

FROM Tasks AS T1

INNER JOIN

任务AS T2

ON T2.StartDate< = T1.StartDate AND

T1.StartDate> ='''20030801''和

T2.StartDate> =' '20030801''

GROUP BY T1.StartDate,T1.TaskName


问候,

jag



SELECT T1.StartDate, T1.TaskName, COUNT(*) AS Cnt
FROM Tasks AS T1
INNER JOIN
Tasks AS T2
ON T2.StartDate <= T1.StartDate AND
T1.StartDate >= ''20030801'' AND
T2.StartDate >= ''20030801''
GROUP BY T1.StartDate, T1.TaskName

Regards,
jag





如果TaskName是唯一的,并给你正确的顺序,那么试试:


select(SELECT COUNT(*)FROM tmp c WHERE c.TaskName< = b.TaskName)as id,

b.TaskName,b.Startdate

来自任务b

按任务名称订购


John


" Surajit Laha" < S _ **** @ rediffmail.com>在消息中写道

新闻:ba ************************** @ posting.google.c om ...
Hi

If TaskName is unique and gives you the correct order then try:

select ( SELECT COUNT(*) FROM tmp c WHERE c.TaskName <= b.TaskName ) as id,
b.TaskName, b.Startdate
from Tasks b
order by TaskName

John

"Surajit Laha" <s_****@rediffmail.com> wrote in message
news:ba**************************@posting.google.c om...
我正在触发如下查询:

SELECT TaskName,StartDate FROMTasks
WHERE StartDate> =''01 -Aug-2003''

现在结果如下:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003



现在我想要的是:

Sl。 No. TaskName StartDate
----------------------------------
1 Task1 01- 2003年8月
2 Task5 10-Oct-2003

如何获得Sl。编号字段(表中不存在)。
我可以这样做吗?

-surajit
I am firing a query like:

SELECT TaskName, StartDate FROMTasks
WHERE StartDate >= ''01-Aug-2003''

Now the result comes as:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003

etc.

Now what I want is this:
Sl. No. TaskName StartDate
----------------------------------
1 Task1 01-Aug-2003
2 Task5 10-Oct-2003
How do I get the Sl. No. field (it does not exist in the table).
Can I do it?

-surajit



Surajit,


我不是说这是一种更好的方式,它只是另一种选择:


SELECT身份( int)as Sl,

任务名称,

StartDate

INTO #Tmp

来自任务

WHERE StartDate> =''01 -Aug-2003''


SELECT * FROM #Tmp


DROP TABLE #Tmp

Shervin


" Surajit Laha" < S _ **** @ rediffmail.com>在消息中写道

新闻:ba ************************** @ posting.google.c om ...
Surajit,

I''m not saying this is a better way, it''s just another option:

SELECT identity(int) as Sl,
TaskName,
StartDate
INTO #Tmp
FROM Tasks
WHERE StartDate >= ''01-Aug-2003''

SELECT * FROM #Tmp

DROP TABLE #Tmp
Shervin

"Surajit Laha" <s_****@rediffmail.com> wrote in message
news:ba**************************@posting.google.c om...
我正在触发如下查询:

SELECT TaskName,StartDate FROMTasks
WHERE StartDate> =''01 -Aug-2003''

现在结果如下:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003



现在我想要的是:

Sl。 No. TaskName StartDate
----------------------------------
1 Task1 01- 2003年8月
2 Task5 10-Oct-2003

如何获得Sl。编号字段(表中不存在)。
我可以这样做吗?

-surajit
I am firing a query like:

SELECT TaskName, StartDate FROMTasks
WHERE StartDate >= ''01-Aug-2003''

Now the result comes as:

TaskName StartDate
--------------------------
Task1 01-Aug-2003
Task5 10-Oct-2003

etc.

Now what I want is this:
Sl. No. TaskName StartDate
----------------------------------
1 Task1 01-Aug-2003
2 Task5 10-Oct-2003
How do I get the Sl. No. field (it does not exist in the table).
Can I do it?

-surajit






这篇关于查询结果中的标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆