我是SQL的新手,我不知道该怎么做。我想对类似对(vin,action)求和一个名为“ total_spending”的汇总,并选择第一个Dealer_name和参考月份年份(这样它就不会创建重复项),并具有类似示例的输出: 输入
from tkinter import *
import tkinter as tk
from tkinter.messagebox import *
global my_list
my_list = ["This is the first sentence , ", "This is the second sentence ,", "this is the third sentence ,", "this is the last sentence "]
def show_answer():
Ans = my_list
blank.insert(0, Ans)
main = Tk()
main.title('Programm')
main.geometry('500x500+300+100')
Button(main, text='Show', command=show_answer).grid(row=30, column=1, sticky=W, pady=4)
Label(main, text="The text is").grid(row=2)
blank = Entry(main)
blank.grid(row=2, column=1, ipadx=50, ipady=50, sticky="NW")
mainloop()
输出
action dealer_name vin Total_spending reference month year
A1 D1 V1 T1 R1 M1 Y1
A2 D2 V2 T2 R1 M1 Y1
A2 D2 V2 T3 R2 M2 Y2
A3 D2 V1 T4 R1 M1 Y1
A4 D1 V2 T5 R1 M1 Y1
A2 D1 V2 T6 R1 M1 Y1
A1 D1 V1 T7 R2 M2 Y2
A4 D1 V2 T8 R2 M2 Y2
A1 D1 V1 T9 R3 M3 Y3
A3 D2 V2 T10 R1 M1 Y1
A3 D2 V1 T11 R2 M2 Y2
答案 0 :(得分:1)
您可以在下面尝试-
select action,dealer_name,vin,sum(Total_spending) as total_spending, reference ,month, year
from tablename
group by action, dealer_name , vin,reference ,month, year