小编gau*_*gul的帖子

如何从表 GORM 中获取工资列的总和

我正在使用 PostgreSQL 和 golang 编写后端。我在获取工资栏总和时遇到问题。

这是我的代码:

    func GetSalarySum(c echo.Context) error {
        db, err := gorm.Open("postgres", "host=localhost port=5433 user=postgres dbname=testone password=root sslmode=disable")
        checkError(err)
        defer db.Close()
        type UpdatedAddress struct {
            City  string `json:"city;"`
            State string `json:"state;"`
            Pin   string `json:"pin;"`
        }
        type UpdatedContact struct {
            ID     uint   `json:"id;"`
            Mobile string `json:"mobile;"`
            Email  string `json:"email;"`
        }
        type NewPerson struct {
            ID        int            `gorm:"primary_key:true;"`
            Firstname string         `json:"firstname;"`
            Lastname  string         `json:"lastname;"`
            Gender    string         `json:"gender;"`
            Salary    uint           `json:salary;`
            Age       uint           `json:"age"`
            Address   UpdatedAddress `json:"address"`
            Contact   UpdatedContact `json:"contact"` …
Run Code Online (Sandbox Code Playgroud)

postgresql go go-gorm go-echo

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

go ×1

go-echo ×1

go-gorm ×1

postgresql ×1