如何删除重复的数据?

时间:2019-05-25 03:08:11

标签: sql sql-server duplicates

我有返回数据且没有重复的问题

我需要获取具有最大日期的com_id,而com_id中没有重复,并且我需要在t_date之前显示com_id的顺序

**

不在乎current_season和season这是另一件事,我只需要获取最大日期的com_id,而不必在t_date之前重复com_id顺序

**


i have this view in db

  

我尝试了这段代码,但结果不正确

import time name = "00" ##this is what we want to change ## def Intro(): print("\n\n\nWelcome to the game.") time.sleep(1) print("This is an attempt to make an interactive text based game.") ## def Creation(): Character_name = input("\nWhat will your Character's name be: ") time.sleep(1) print("\nWelcome to the game " + Character_name + " \n" ) time.sleep(1.5) Character_class = input("In one word, name " + Character_name + "'s profession: ") t00n = Character_name + " the " + Character_class global name ##here I am using the global keyword name = t00n time.sleep(1) print("\n" + t00n + "\n") time.sleep(2) next_func = input("When ready type 'next' to begin.\n>>>:") if next_func == "next": segway() else: Jump() ## def Jump(): Jump_Prompt = input("Just 'Jump' on in\n>>>: ") if Jump_Prompt == "Jump": segway1() else: Jump() ## def segway(): print("A room with options to choose from") prompt() class Character: def __init__(self, name, HP, full_HP, AtS, AR): self.name = name ##should = t00n now? self.hp = HP self.full_HP = full_HP self.AtS = AtS self.AR = AR def stat_bar(self): return '{} {} {} {} {} {}'.format("[Name:]", self.name, "[HP:]", self.hp, "[Max HP:]", self.full_HP) Player1 = Character(name, 100, 100, 1, 0) ## def prompt(): _pr = input("<<< " + Character.stat_bar(Player1) + " >>> \n") return _pr #Begin Intro() Creation() segway() ##The prompt() function still displays the name as 00 even tho the creation() function is using the 'global' keyword to change the 'name' variable to the user input.

我的预期结果是

124235623(第1个月)
123457(第1个月)
1111(第2个月(该小组的最大月份)
123(第5个月(该小组的最大月份)

3 个答案:

答案 0 :(得分:1)

我认为您需要这样做:

SELECT com_id, max(t_date)
FROM vw_vsa
where current_season=season
GROUP BY com_id
order by max(t_date)

答案 1 :(得分:0)

尝试从DISTINCT中使用clasule

SELECT DISTINCT com_id FROM vw_vsa where current_season=season GROUP BY com_id,t_date order by t_date

答案 2 :(得分:0)

根据您的描述,order by应该只是max(t_date)。但预期结果是,您似乎想根据month

订购
SELECT com_id, max(t_date)
FROM   vw_vsa
where  current_season = season
GROUP BY com_id
order by month(max(t_date))