ID是表table1中的自动增长的字段,我想通过上述语句生成一个带有行号的字段rowno,SQL如何如何写?
7 个解决方案
#1
ACCESS没有这样的函数
select a.id,count(b.id) from tt a left join tt b
on a.id<=b.id
select a.id,count(b.id) from tt a left join tt b
on a.id<=b.id
#2
我在ACCESS中创建的查询,却提示如下错误:
在试图执行的查询中不包含作为聚合函数一部分的特定表达式"id"。
为何这样?
#3
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id group by a.id
on a.id <=b.id group by a.id
#4
非常感谢!
但是又有一个问题:
因为我在实际查询中表中以字符串字段进行这样的过滤:WHERE keywords like '%ABC%'
请问where语句应该放在何处呢?
#5
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE keywords like '%ABC%'
group by a.id
on a.id <=b.id
WHERE keywords like '%ABC%'
group by a.id
#6
wwwwb:
我是这样写的:
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like '%ABC%'
group by a.id
结果却查询不出来数据!
我是这样写的:
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like '%ABC%'
group by a.id
结果却查询不出来数据!
#7
如果写成这样:
select a.id,count(b.id) AS rowno from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like ' *ABC*'
group by a.id
查询结果如下:
id rowno
1 6
2 5
4 3
5 2
但是不是我想得到的结果:
id rowno
1 1
2 2
4 3
5 4
请问如何实现呢?
select a.id,count(b.id) AS rowno from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like ' *ABC*'
group by a.id
查询结果如下:
id rowno
1 6
2 5
4 3
5 2
但是不是我想得到的结果:
id rowno
1 1
2 2
4 3
5 4
请问如何实现呢?
#1
ACCESS没有这样的函数
select a.id,count(b.id) from tt a left join tt b
on a.id<=b.id
select a.id,count(b.id) from tt a left join tt b
on a.id<=b.id
#2
我在ACCESS中创建的查询,却提示如下错误:
在试图执行的查询中不包含作为聚合函数一部分的特定表达式"id"。
为何这样?
#3
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id group by a.id
on a.id <=b.id group by a.id
#4
非常感谢!
但是又有一个问题:
因为我在实际查询中表中以字符串字段进行这样的过滤:WHERE keywords like '%ABC%'
请问where语句应该放在何处呢?
#5
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE keywords like '%ABC%'
group by a.id
on a.id <=b.id
WHERE keywords like '%ABC%'
group by a.id
#6
wwwwb:
我是这样写的:
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like '%ABC%'
group by a.id
结果却查询不出来数据!
我是这样写的:
select a.id,count(b.id) from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like '%ABC%'
group by a.id
结果却查询不出来数据!
#7
如果写成这样:
select a.id,count(b.id) AS rowno from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like ' *ABC*'
group by a.id
查询结果如下:
id rowno
1 6
2 5
4 3
5 2
但是不是我想得到的结果:
id rowno
1 1
2 2
4 3
5 4
请问如何实现呢?
select a.id,count(b.id) AS rowno from tt a left join tt b
on a.id <=b.id
WHERE a.keywords like ' *ABC*'
group by a.id
查询结果如下:
id rowno
1 6
2 5
4 3
5 2
但是不是我想得到的结果:
id rowno
1 1
2 2
4 3
5 4
请问如何实现呢?