- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望你们好人!我在 SELECT 三个不同的表和 SUM 那里有一个大问题 Total 这样我就可以得到这三个表的总计。表格如下,我只是提到了一些字段:
1:付款
id idnumber school_fee trans_fee
1 va03 10000 20000
2:payment_one
id idnumber school_fee trans_fee
1 va01 10000 30000
3:payment_two
id idnumber school_fee trans_fee
1 va02 40000 50000
我已经从每个表中得到“总计”,我想要的是对我得到的那些总计求和,从这三个表中得到总计。
这是我的 php 代码;
1:付款方式:
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
2:payment_one
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment_one
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment_one
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
3:payment_two
<?php
//include mysql connect
if (isset($_GET['query']))
{
$query=$_GET['query'];
// Instructions if $_POST['value'] exist
}
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum
length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT
*,SUM(school_fee+trans_fee)
As Total FROM payment_two
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
$raw_results2 = mysql_query("SELECT * FROM payment_two
WHERE (`class` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query
is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use
`title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %'
...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){
if(mysql_num_rows($raw_results2) > 0){
// if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
while($results2 = mysql_fetch_array($raw_results2)){
// $results = mysql_fetch_array($raw_results) puts data from database into
array, while it's valid it does the loop
// posts results gotten from database(title and text) you can also show id
($results['id'])
}{
echo " Total amount of money payed by " .$results['class']
." "."class is " . $results ['Total'] . " /=Tshs";
echo"<br>"; echo"<br>";
}
}
}
}
}
?>
如有任何帮助,我将不胜感激。
最佳答案
如果我没理解错的话,你所有的三个表 [payment][payment_one][payment_two] 都有相同的列:id、idnumber、school_fee trans_fee。
您可以使用一个单独的表来代替,并通过引入一个新的列来区分它们:tablenum,然后很容易获得您想要的。 请注意[id]和[tablenum]现在都是主键(复合主键)。
新表架构和数据将是(我不太确定您的 idnumber 列的用途):
[payment]
id tablenum idnumber school_fee trans_fee
1 0 va03 10000 20000
1 1 va01 10000 30000
1 2 va02 40000 50000
SQL 示例:
SELECT
school_fee,
trans_fee,
(school_fee + trans_fee) as 'total'
FROM payment WHERE id=1
关于php - 如何从三个不同的表php中查询总计的SELECT SUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19753935/
我有这个示例代码: #include #include int main() { Eigen::MatrixXf M = Eigen::MatrixXf::Random(1000, 1000)
我有一个像这样的数据框: +-----+--------+ |count| country| +-----+--------+ | 12| Ireland| | 5|Thailand| +-
我想要 SUM(tot_bill_1+tot_bill_2) AS 总计,但这不起作用 SELECT *, IF(SUM(bill_1) IS NULL, '99', SUM(bill_1)) AS
如果我们有两个矩阵 X 和 Y,都是二维的,现在在数学上我们可以说:sum(X-Y)=sum(X)-总和(Y). Matlab 哪个效率更高?哪个更快? 最佳答案 在我的机器上,sum(x-y) 对于
我正在运行 Hive 1.1.0 并看到对于两个 bigint 列,active_users 和 inactive_users,SUM(active_users + inactive_users) <
是否可以在一个选择查询中求和? 类似这样的事情: SELECT id, SUM(current_price - bought_price)*amount AS profit FROM purchase
这是一个相当奇怪的结果。我希望这些具有相同的产量。 下面还有从数据库中提取的 excel 链接。 https://twentius.opendrive.com/files?89038281_muoyg
我必须对 2 个字段求和,然后再求和。从性能的角度来看,先添加字段还是在对列求和之后添加字段有什么区别? 方法 1 = SELECT SUM(columnA + columnB) 方法 2 = SEL
这是一个经典问题,但我很好奇是否有可能在这些条件下做得更好。 问题:假设我们有一个长度为4*N的排序数组,即每个元素重复4次。请注意,N 可以是任何自然数。此外,数组中的每个元素都受制于 0 A. 执
我正在编写一个 Pig 程序,该程序加载一个用制表符分隔整个文件的文件 例如:名称 TAB 年份 TAB 计数 TAB... file = LOAD 'file.csv' USING PigStora
我有一个包含以下字段的表: EmpID, Code, Amount, TransDate, CM, CMDate 我想要进入数据网格的是 SUM所有的Amount具有相同的 Code和 SUM CM具
我有两个单独的查询用于提取报告信息。一年效果很好。但是,如果一个月超过 1 年,则不会显示正确的响应。 这是我的两个查询: select SUM(rpt_complete.total) total,
我想查询一个团队的积分。通过在列上执行 SUM + 来自具有相同团队 ID 的另一个表的 SUM 来添加这些点。我试着这样写: SELECT k.id, s.fylke, s.
这个问题在这里已经有了答案: How to deal with floating point number precision in JavaScript? (47 个回答) Unexpected
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 5 年前。 Improve
我已经找了一段时间,但找不到这个问题的答案(也许我没有搜索正确的术语或其他东西)。基本上,我有一个数据库,每个日期有任意数量的条目。我需要取包含条目的最后 X 天的总和(忽略没有条目的天数)。我知道如
我正在尝试获取 B 行中包含 A 行中某个值的所有值中的一些值。我猜这个问题很简单。 这是我的查询: =QUERY('Sheet1'!$A$16:D, "Select sum(D) Where C c
我正在尝试运行以下查询,但出现以下错误: You have an error in your SQL syntax; check the manual that corresponds to your
我有一个 tableA,其中包含以下结构 我将此结构修改为如下所示的tableB,以减少行数,并且类别是固定长度的 假设我在 tableA 中修改为新结构后有 210 万条数据,tableB 仅包含
我的表在 Postgres 中的数据: id user_id sell_amount sell_currency_id buy_amount buy_currency_id type
我是一名优秀的程序员,十分优秀!