多表查询的问题,mysql查询有数据,编写models的时候没传数据(数量是有传值,其他参数没有传值)(...

栏目: 数据库 · 发布时间: 6年前

内容简介:package products import ( "erp/models" "github.com/astaxie/beego/orm" ) type Product_Inventorys struct { Id int64 Name string Formate string Unit string Warehouse string C_name string Purchase string Price string Quantity string } func init() { orm.Registe
多表查询的问题,mysql查询有数据,编写models的时候没传数据(数量是有传值,其他参数没有传值)(...

多表查询的问题,mysql查询有数据,编写models的时候没传数据(数量是有传值,其他参数没有传值)(models联表查询创建,数据库没有表),各位大神请教下

zhong ·· 2 次点击 ··开始浏览    

package products import ( "erp/models" "github.com/astaxie/beego/orm" ) type Product_Inventorys struct { Id int64 Name string Formate string Unit string Warehouse string C_name string Purchase string Price string Quantity string } func init() { orm.RegisterModel(new(Product_Inventory)) } //统计仓库存量 func ListInvent()(num int64,err error, invent []Product_Inventorys) { qb, _ := orm.NewQueryBuilder("mysql") qb.Select("i.id As Id", "p.name As Name", " p.format As Formate", "p.unit As Unit","w.w_name As Warehouse","c.name As C_name","p.purchase As Purchase", "p.sales As Price","i.quantity As Quantity"). From(models.TableName("product_inventory i,pms_product p,pms_product_category c,pms_product_warehouse w") ). Where("i.product=p.id and i.warehouse=w.w_id and p.c_id=c.id") sql := qb.String() o := orm.NewOrm() var invents []Product_Inventorys nums, errs := o.Raw(sql).QueryRows(&invents) return nums,errs,invents } [ORM]2019/01/15 20:08:17 -[Queries/default] - [ OK / db.Query / 233.0ms] - [SELECT i.id As Id, p.name As Name, p.format As Formate, p.unit As Unit, w.w_name As Warehouse, c.name As C_name, p.purchase As Purchase, p.sales As Price, i.quantity As Quantity FROM pms_product_inventory i,pms_product p,pms_product_category c,pms_product_warehouse w WHERE i.product=p.id and i.warehouse=w.w_id and p.c_id=c.id] [{0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 } {0 }] ![1.png](https://static.studygolang.com/190115/3b74cc00d81cbf5d382ad55f5b26e383.png) ![2.png](https://static.studygolang.com/190115/29d23d7df32da14e170075a0931b1997.png)


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

上瘾

上瘾

[美] 尼尔·埃亚尔、[美] 瑞安·胡佛 / 钟莉婷、杨晓红 / 中信出版集团 / 2017-5 / 49.00元

——为什么我们会习惯性地点开某个App? ——这种使用习惯到底是如何养成的? ——为什么有些产品能让我们戒不掉,而其他的产品却不行? ——是否有什么秘诀能让用户对你的产品形成使用习惯,欲罢不能? 《上瘾》揭示了很多让用户形成使用习惯,甚至“上瘾”的互联网产品服务背后的基 本设计原理,告诉你怎样打造一款让用户欲罢不能的产品。作者根据自己多年的研究、咨询及实际经验,提出了新颖而......一起来看看 《上瘾》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器