我有返回数据且没有重复的问题
我需要获取具有最大日期的com_id,而com_id中没有重复,并且我需要在t_date之前显示com_id的顺序
**
**
我尝试了这段代码,但结果不正确
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个月(该小组的最大月份)
答案 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))