正确的 SQL 显示名称而不是 ID Reportico 的查询

Proper SQL Query for Displaying the name instead of ID Reportico

我有 3 个 table,工单、类别和子类别。在 Yii2 Reportico 中,为了生成报告,您需要配置 SQL 查询。

SELECT id, time_start, time_end, details, room_no, employee_id, category_id, sub_cat_id  FROM tickets

这是我的 SQL 获取票证 table 数据的查询,而不是显示 category_id 和 sub_cat_id。我想显示 category_name 和 sub_category,正确的 sql 语法是什么?

你可以尝试这样的事情,看看你是否得到类别名称:

SELECT t.id, t.time_start, t.time_end, t.details, t.room_no, t.employee_id, 
c.category_name , s.sub_category
FROM tickets as t inner join Category as c on t.category_id=c.id inner join
sub_cat as s on t.sub_cat_id=s.id and s.category_id=c.id

我不知道您在类别和子类别 table 中的字段名称,但如果它适用于类别,请尝试以类似方式添加子类别 table,或者 post 两个 table 的字段列表。