我尝试创建一个查询来选择表中的所有行有一列名newtotalMySQL中的所有有一列的总和行
的总和这是我的查询
SELECT *
FROM tbl_activities
,(SELECT SUM(db_newtotal) as total FROM tbl_activities) {$sql}
{$ SQL}在这里列名=从SEACH表单输入
但我有此错误:
Every derived table must have its own alias
我试着这样做:
SELECT *
FROM tbl_activities
,(SELECT SUM(db_newtotal) as total FROM tbl_activities) as Table {$sql}
但我有此错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Table where db_projectname='Barbara Bui'' at line 1
我打印查询,这是输出
SELECT *
FROM tbl_activities
,(SELECT SUM(db_newtotal) as total FROM tbl_activities) as Table
where db_projectname='Barbara Bui'
输出我想应该是这样的:以项目名称命名LL记录='Barbara Bui'用总和newtotal
projectname location Cost
Barbara Bui verdun 100
Barbara Bui kaslik 200
Barbara Bui achrafieh 500
Total 800
查询
SELECT * FROM tbl_activities
union all
select db_id,db_category,db_subcategory,db_taskname,db_predecessors,db_unit,db_qty,db_wo,db_duration,db_startdate,db_enddate,db_asd,db_add,db_transferredto,db_prb,db_anotes,db_aduration,db_projectname,db_A,db_AA,db_AAA,db_cost,db_status,db_room,db_floor,db_date,sum(db_newtotal) as total from tbl_activities
{$sql}
你可以请检查更新以上的查询它给我这个错误使用的SELECT语句有不同数量的列 – Developer
@Developer - 更新我的答案。 – GurV