Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.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 如何从联接查询中删除重复值_Sql_Sql Server 2008 - Fatal编程技术网

Sql 如何从联接查询中删除重复值

Sql 如何从联接查询中删除重复值,sql,sql-server-2008,Sql,Sql Server 2008,大家好,我怎样才能从这个join语句中删除重复记录 SELECT std_info.Reg_no, std_info.std_name, tut_fee.fee_month, class.class_name FROM std_info INNER JOIN tut_fee on std_info.Reg_no=tut_fee.Reg_no INNER JOIN promot on std_info.Reg_no=promot.Reg_no INNER JOIN class

大家好,我怎样才能从这个join语句中删除重复记录

SELECT  std_info.Reg_no, std_info.std_name, tut_fee.fee_month, class.class_name 
FROM std_info 
  INNER JOIN tut_fee on std_info.Reg_no=tut_fee.Reg_no 
  INNER JOIN promot on std_info.Reg_no=promot.Reg_no 
  INNER JOIN class on class.class_id=promot.class_id
WHERE std_info.Reg_no not in (SELECT Reg_no 
                              FROM tut_fee 
                              WHERE tut_fee.fee_month=3
                                AND tut_fee.fee_year=2014)
它给出了结果

 Reg_no     std_name    fee_month   class_name

 1. A01      name1         1           2nd
 2. A01      name1         2           2nd
 3. A02      name2         1           3rd
 4. A02      name2         2           3rd

谢谢大家。

数据来自“tut\u fee.fee\u MOUNT”列。

首先我在数据库中创建了临时表,命名为fee\u temp,然后插入查询给出的记录。然后使用Row_Number函数进行分区,并删除所有列出多条记录的记录。就像下面给出的一样

   insert into Fee_temp SELECT   std_info.Reg_no,std_info.std_name,tut_fee.fee_month,class.class_name FROM
std_info Left  JOIN tut_fee on std_info.Reg_no=tut_fee.Reg_no Left JOIN promot on  std_info.Reg_no=promot.Reg_no Left JOIN
class on class.class_id=promot.class_id
WHERE std_info.Reg_no not in (select  Reg_no FROM tut_fee where  tut_fee.fee_month=3   and tut_fee.fee_year=2014)
 SELECT * from Fee_temp
  With A as
 (
 select Fee_temp.Reg_no,Fee_temp.std_name,Fee_temp.fee_month,Fee_temp.class_name,ROW_NUMBER() 
 OVER (Partition by Reg_no ORDER BY Fee_temp.std_name) As Number from Fee_temp
)
DELETE FROM A WHERE Number>1
SELECT * FROM Fee_temp

我没有看到任何重复的!名称1和名称2重复了两次,希望显示像A01名称1第二个A02名称2第三个这样的内容以便重播