select top 1 distinct a.userid,b.description,count(*)
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
order by a.userid,b.description desc
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
order by a.userid,b.description desc
解决方案 »
- 判断一个字段的值是否为NULL的SQL语句?
- 谁能讲讲这Chinese_PRC_CI_AS 是什么意思呀?
- 建立数据库连接的问题 急 sp_addlinkedserver 100分
- SQL查询问题
- 两个问题,请帮忙!!先谢谢
- 各位大哥,帮帮我吧:[OLE/DB provider returned message: 无法启动应用程序。工作组信息文件丢失,或是已被其它用户以独占方式打开。]
- 问题描述3
- 查询速度问题
- 要写一个函数,参数为:表名+字段名,返回这个表的这个字段是否是构成主键的其中一个列?
- sql server存储过程用什么编辑比较好??
- substring这个函数,当字符串超过10个十个的长度时,就会失效
- 请问如何比较时间?
Is it right?select distinct a.userid,b.description,count(*)
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
having a.userid=2
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
order by a.userid,b.description desc
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统' and a.userid=2
group by a.userid,b.description
(
select distinct a.userid,b.description,count(*)
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
order by a.userid,b.description
) k
我在查询分析器下按你的方法执行却提示如下:
服务器: 消息 1033,级别 15,状态 1,行 8
除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。
我想知道你回复的k代表什么? 当我将order by子句去掉后依然报错:第 7 行: ')' 附近有语法错误。
select count(*) from
(
select distinct a.userid,b.description,count(*)
from table1 a,table2 b
where a.userid = b.userid and a.description ='进入系统'
group by a.userid,b.description
)
我实在看不出有什么错,是否select count(*)也不能用在嵌套的语句中?
我没有你的数据库,不能测试
如果需要你可以把你的数据库给我发过来
[email protected]
附件不要大于1M
我的真实SQL语句如下:select distinct a.yhh,b.description,count(*)
from r_yhrz a,p_user b
where a.yhh = b.id and a.description ='进入系统'
group by a.yhh,b.description
order by a.yhh,b.description我的目的还是想用一句得到上面结果的记录数在我使用了你的方法后提示:服务器: 消息 8155,级别 16,状态 2,行 1
没有为第 3 列(属于 'k')指定列。
对应SQL:
select count(*) from
(
select distinct a.yhh,b.description,count(*)
from r_yhrz a, p_user b
where a.yhh = b.id and b.description ='进入系统'
group by a.yhh,b.description
) k
不好意思,上上楼的错误已经调试,SQL如下:
select count(yhh) as k from
(
select distinct a.yhh,b.description,count(*) as g
from r_yhrz a, p_user b
where a.yhh = b.id and b.description ='进入系统'
group by a.yhh,b.description
) k结果:k
0
问题是:就象我每一次发贴时提到的,应该有两条记录才对
不好意思,上上楼的写错了,问题已经解决。
我还想知道下面的SQL为什么错:
select top 1 distinct a.yhh,b.description,count(*)
from r_yhrz a,p_user b
where a.yhh = b.id and a.description ='进入系统'
group by a.yhh,b.description
order by a.yhh,b.description 我想得到结果中第一条记录
正确的SQL就为:
select top 1 * from
(
select distinct a.yhh,b.description,count(*) as num
from r_yhrz a, p_user b
where a.yhh = b.id and a.description ='进入系统'
group by a.yhh,b.description
)
k
问题全部解决。
再次感谢Taken(铁拳)参与