Php 从数据库表中的特定列添加数据
我从一张表中得到了这些数据。例如,我有一个名为tbl_points的点表。 tbl_积分包括:Php 从数据库表中的特定列添加数据,php,mysql,Php,Mysql,我从一张表中得到了这些数据。例如,我有一个名为tbl_points的点表。 tbl_积分包括: ptsID, team1, team2. 1 10 20 2 20 10 3 30 5 如何创建一个查询来汇总团队1和团队2的积分?未测试: SELECT SUM(p1.team1) AS team1_score , SUM(p2.team2) AS team2_score FROM tbl_point
ptsID, team1, team2.
1 10 20
2 20 10
3 30 5
如何创建一个查询来汇总团队1和团队2的积分?未测试:
SELECT SUM(p1.team1) AS team1_score
, SUM(p2.team2) AS team2_score
FROM tbl_points AS p1
, tbl_points AS p2
以下查询:
SELECT
SUM(team1) AS team1_points,
SUM(team2) AS team2_points
FROM
tbl_points
将为您提供一个单行表格,结果如下:
| team1_points | team2_points |
| 60 | 35 |
此外,使用name
tbl_points
也不好。最好不要使用前缀。只需说出你的表格点
,就足够清楚了。@jetoox,Riateche有一个很好的理由,那就是不要使用前缀“tbl”。。。显然是从表中查询。。。还要注意列名不要使用可能是“保留字”的内容,如日期、名称、时间、计数、组等。@DRapp使用tbl作为前缀已经是我们编码惯例的一部分。你为什么要用保留字?我在上面用过吗?