Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server Sql Server查询未给出正确的结果_Sql Server_Sql Server 2008 - Fatal编程技术网

Sql server Sql Server查询未给出正确的结果

Sql server Sql Server查询未给出正确的结果,sql-server,sql-server-2008,Sql Server,Sql Server 2008,我有表格sent时事通讯。此表有以下列 1. ID 2. Surah_no 3. Aayt 4. Sent_date, 5. Sent_By 我想 select id ,surah_no ,aayt ,sent_date (MAx) 发送人,Surah\u no和Aayt有多条记录,如Id ID Surah_no aayt sent_date Sent_By 1 1 1 2013-04-08 1

我有表格
sent时事通讯
。此表有以下列

1. ID
2. Surah_no
3. Aayt
4. Sent_date,
5. Sent_By
我想

select id
     ,surah_no
     ,aayt
     ,sent_date (MAx)
发送人
Surah\u no
Aayt
有多条记录,如Id

ID  Surah_no  aayt  sent_date                 Sent_By

1   1         1     2013-04-08 19:39:26.127   Test
2   1         1     2013-04-08 20:03:24.920   Test
3   1         1     2013-04-08 19:39:26.127   Test
4   1         1     2013-04-08 20:03:24.920   Test
5   1         1     2013-04-08 20:19:26.033   User3
6   1         1     2013-04-08 20:24:47.890   User3

select Count(*)
     ,surano
     ,Aaytno
     ,MAx(SENT_DATE) 
from sentnewsletters 
group by SuraNo
     ,Aaytno

我需要你的身份证,还要你寄过来

select Count(*)
     ID
     ,surano
     ,Aaytno
     ,MAx(SENT_DATE) ,
      Sent_by
from sentnewsletters 
group by SuraNo
     ,Aaytno
你可以用

select Count(*) as Count
     ,surano
     ,Aaytno
     ,MAx(SENT_DATE) as SentDate ,
      Sent_by
from sentnewsletters 
group by SuraNo
     ,Aaytno
     ,Sent_by
您不能在
ID
上分组,因为每个记录都是不同的,您将获得与仅使用

select   1 as Count
         ,surano
         ,Aaytno
         ,SENT_DATE,
          Sent_by
    from sentnewsletters 
结果会是

Count Surah_no  aayt  sent_date                 Sent_By
4      1         1     2013-04-08 20:03:24.920   Test
2      1         1     2013-04-08 20:24:47.890   User3

…它返回了什么?您正在同时使用
Surah\u no
/
Surah
Aayt
/
Aaytno
。我想这些是相同的字段?你能相应地更新代码吗?你看到错误了吗?或者只是一个不正确的(预期的)结果?您可以通过获得发送的
,但不能获得
ID
,因为您需要分组?