首先,我不会对SQL语句有所了解,我可以做一个基本的但是做一个小组,sum和datediff让我对我想要做的事感到困惑。
我想要完成的是按照以下方式将我的条目分解到数据库中,为卡车,拖车和定义燃料购买的燃料总量,花费的总金额,以及能够每月或按季度执行的操作卡车。 我知道对于基本的人来说会是这样的,但对于更复杂的SQL语句,我完全迷失了它。 基本声明就像这样
TNumber = Request.Cookies("Truck_Number")
MySQL= "SELECT * FROM Fueling_Information WHERE Truck_Number = TNumber"
但是要做一个覆盖表格中所有字段的小组能够做我想做的事情会更加复杂,这就是我想要解决的问题。 例如,在下面添加每个州的所有交易,并按卡车号码和按月或按季度计算总额。
State Truck Fuel Trailer Fuel Total Price
AL 101.05 25.667 900.57
IL 150.95 12.650 1075.30
MS 75.25 10.500 210.50
访问在其设计中显示的语句按州分组事务,但它有多个相同的状态,如:
State Truck Fuel Trailer Fuel Total Price
AL 101.05 25.667 900.57
AL 271.05 20.167 600.00
IL 150.95 12.650 1075.30
MS 75.25 10.500 210.50
MS 75.25 10.500 210.50
MS 75.25 10.500 210.50
这不是我真正想要的,因为它显示了多次购买多次而不是1次状态的状态,每个列的总和基于truck_number = to TNumber
选择和隔离的月份或季度
SELECT DISTINCTROW
Fueling_Information.ID,
Fueling_Information.Fuel_Location_Name,
Fueling_Information.Fuel_Price_DEF,
Format$([Fueling_Information].[Fuel_Date_Added],'mmmm yyyy')
AS [Fuel_Date_Added By Month],
Fueling_Information.Fuel_Truck_Number,
Fueling_Information.Fuel_Trailer_Number,
Fueling_Information.Fuel_City,
Fueling_Information.Fuel_State,
Fueling_Information.Fuel_Station_Number,
Fueling_Information.Fuel_Station_Zip,
First(Fueling_Information.Fuel_Address) AS [First Of Fuel_Address],
Sum(Fueling_Information.Fuel_Price) AS [Sum Of Fuel_Price],
Sum(Fueling_Information.Fuel_Gallons_Truck) AS [Sum Of Fuel_Gallons_Truck],
Sum(Fueling_Information.Fuel_Gallons_DEF) AS [Sum Of Fuel_Gallons_DEF],
Sum(Fueling_Information.Fuel_Gallons_Reefer) AS [Sum Of Fuel_Gallons_Reefer],
Sum(Fueling_Information.Fuel_Total_Price) AS [Sum Of Fuel_Total_Price]
FROM Fueling_Information
GROUP BY
Fueling_Information.ID,
Fueling_Information.Fuel_Location_Name,
Fueling_Information.Fuel_Price_DEF,
Format$([Fueling_Information].[Fuel_Date_Added],'mmmm yyyy'),
Fueling_Information.Fuel_Truck_Number,
Fueling_Information.Fuel_Trailer_Number,
Fueling_Information.Fuel_City,
Fueling_Information.Fuel_State,
Fueling_Information.Fuel_Station_Number,
Fueling_Information.Fuel_Station_Zip,
Year([Fueling_Information].[Fuel_Date_Added])*12+
DatePart('m',[Fueling_Information].[Fuel_Date_Added])-1;
我在哪里放"WHERE Truck_Number=102"
先谢谢你。