我想用 Gorm 编写以下 SQL 查询:
SELECT count(*)
FROM (
SELECT DISTINCT ON(t1.number) t1.number,
t1.id
FROM "tbl_phone_books" AS t1
WHERE (customer_id = 100)
) AS phone
LIMIT 5 OFFSET 0;
我写了这段代码,但它不能正常工作:
Db.Debug().
Model(models.TblPhoneBook{}).
Select("distinct on(number) number,id).
Where("customer_id = ? , customerId).
Offset(offset).
Limit(5).
Count(&response)
db.Table("tbl_phonebooks").Select("distinct on(number) number, id").Where("customer_id = ?", 100).Group("number, id").Limit(5).Offset(0).Count(&count)