- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个疑问:
(SELECT b904_Vasarlas.PrintedFigure as Image,
b904_Vasarlas.ProductColor as Color,
SUM(b904_Vasarlas.QTY) as QTY
FROM `b904_Vasarlas`
GROUP BY 1, 2)
ORDER by 1, 2
具有良好的输出:
Image;Color;QTY
"villamos","blue","5"
"villamos","pink","5"
"virag","blue","5"
"virag","pink","5"
"virag2","blue","5"
"virag2","pink","5"
"vitorlas","blue","5"
"vitorlas","pink","5"
"vonat","blue","5"
"vonat","pink","5"
"zaszlo","blue","5"
"zaszlo","pink","5"
"zsiraf","blue","15"
"zsiraf","pink","15"
和
(SELECT b904_Eladas.PrintedFigure as Image,
b904_Eladas.ProductColor as Color,
SUM(b904_Eladas.QTY) as QTY
FROM `b904_Eladas`
GROUP BY 1, 2)
ORDER by 1, 2
具有良好的输出:
Image;Color;QTY
"golya","blue","20"
"golya","pink","10"
"hajokormany","blue","20"
"hajokormany","pink","10"
"macska","blue","10"
"macska","pink","10"
"malac","blue","10"
"malac","pink","10"
"villamos","blue","3"
"villamos","pink","3"
"virag","blue","3"
"virag","pink","3"
"virag2","blue","4"
"vitorlas","blue","5"
"vitorlas","pink","5"
"vonat","blue","5"
"vonat","pink","5"
"zaszlo","blue","15"
"zaszlo","pink","5"
"zsiraf","blue","16"
"zsiraf","pink","11"
如何通过一个按图像和颜色列分组的 mysql 查询来获取两个表的 QTY 列的差异?
<小时/>最后我使用了这段较长的代码,但我认为我可以通过更简单的一个查询字符串来解决问题。
$Eladasok = array();
$ElLoop = 0;
$GyartasQuery = '(SELECT ' . $DBConnection[1] . '_Vasarlas.PrintedFigure as RaktarKep, ' . $DBConnection[1] . '_Vasarlas.ProductColor as RaktarSzin, SUM(' . $DBConnection[1] . '_Vasarlas.QTY) as RaktarQTY FROM `' . $DBConnection[1] . '_Vasarlas` GROUP BY 1, 2) ORDER by 1, 2';
$EladasQuery = '(SELECT ' . $DBConnection[1] . '_Eladas.PrintedFigure as EladasKep, ' . $DBConnection[1] . '_Eladas.ProductColor as EladasSzin, SUM(' . $DBConnection[1] . '_Eladas.QTY) as EladasQTY FROM `' . $DBConnection[1] . '_Eladas` GROUP BY 1, 2) ORDER by 1, 2';
$GyartasResult = mysql_query($GyartasQuery);
$EladasResult = mysql_query($EladasQuery);
while(false !== $EladasContent = mysql_fetch_assoc($EladasResult)) {
$new_array[] = $EladasContent;
$Eladasok[$new_array[$ElLoop][EladasKep] . '-' . $new_array[$ElLoop][EladasSzin]] = $EladasContent[EladasQTY];
$ElLoop++;
}
while(false !== $GyartasContent = mysql_fetch_assoc($GyartasResult)) {
if (($GyartasContent[RaktarQTY] - $Eladasok[$GyartasContent[RaktarKep] . '-' . $GyartasContent[RaktarSzin]]) <= 0) {
$Cellcolour = ' bgcolor="#DDDDDD"';
$CellHighlight = ' bgcolor="#FFBBBB"';
} else {
$Cellcolour = '';
$CellHighlight = '';
}
echo'
<tr><td align=center' . $CellHighlight . '>'.++$RoNo.'</td>
<td' . $Cellcolour . '>' . $GyartasContent[RaktarKep] . ' - ' . $GyartasContent[RaktarSzin] . '</td>
<td' . $Cellcolour . '>' . intval($GyartasContent[RaktarQTY]) . '</td>
<td' . $Cellcolour . '>' . intval($Eladasok[$GyartasContent[RaktarKep] . '-' . $GyartasContent[RaktarSzin]]) . '</td>
<td' . $Cellcolour . '>' . intval($GyartasContent[RaktarQTY] - $Eladasok[$GyartasContent[RaktarKep] . '-' . $GyartasContent[RaktarSzin]]).
'</td></tr>';
}
echo '</tr></table></div>';
最佳答案
数据库1的内容:
从b904_vasarlas
中选择PrintedFigure
、ProductColor
、QTY
(Name, color, QTY)"villamos","blue","5""villamos","pink","5""virág","blue","5""virág","pink","5""virág2","blue","5""virág2","pink","5""vitorlás","blue","5""vitorlás","pink","5""vonat","blue","5""vonat","pink","5""zsiráf","blue","5""zsiráf","pink","5""zászló","blue","5""zászló","pink","5""zsiráf","blue","10""zsiráf","pink","10"
The content of database2:
SELECT PrintedFigure
, ProductColor
, QTY
FROM b904_eladas
(Name, color, QTY)"vitorlás","blue","5""vitorlás","pink","5""vonat","blue","5""vonat","pink","5""zsiráf","blue","5""zsiráf","pink","5""zászló","blue","5""zászló","pink","5""zsiráf","blue","5""zászló","blue","10""zsiráf","blue","6""zsiráf","pink","6""gólya","blue","10""gólya","pink","10""hajókormány","blue","10""hajókormány","pink","10""macska","blue","10""macska","pink","10""malac","blue","10""malac","pink","10""villamos","blue","3""villamos","pink","3""virág","blue","3""virág","pink","3""virág2","blue","4""gólya","blue","10""hajókormány","blue","10"
I need the difference of column called QTY when PrintedFigure AND the product color is same in booth databases.
Your result is wrong:
Image,Color,QtyV,QtyE,Qty,QtyOtherWay "gólya","blue","0","0","-20","-20""gólya","pink","0","0","-10","-10""hajókormány","blue","0","0","-20","-20""hajókormány","pink","0","0","-10","-10""macska","blue","0","0","-10","-10""macska","pink","0","0","-10","-10""malac","blue","0","0","-10","-10""malac","pink","0","0","-10","-10""villamos","blue","5","5","2","2""villamos","pink","5","5","2","2""virág","blue","5","5","2","2""virág","pink","5","5","2","2""virág2","blue","5","5","1","1""virág2","pink","5","5","5","5""vitorlás","blue","5","5","0","0""vitorlás","pink","5","5","0","0""vonat","blue","5","5","0","0""vonat","pink","5","5","0","0""zászló","blue","10","10","-5","-5""zászló","pink","5","5","0","0""zsiráf","blue","45","45","13","13""zsiráf","pink","30","30","8","8"
I have exactly same problem before when I tried using join and union.
The result is good with code using two queries and while loop for array creation:
# Name and color Difference1 villamos - blue 22 villamos - pink 23 virág - blue 24 virág - pink 25 virág2 - blue 16 virág2 - pink 57 vitorlás - blue 08 vitorlás - pink 09 vonat - blue 010 vonat - pink 011 zászló - blue -1012 zászló - pink 013 zsiráf - blue -114 zsiráf - pink 4
I am asking the solution of one query because I want to cancel using this loop:
while(false !== $EladasContent = mysql_fetch_assoc($EladasResult)) {
$new_array[] = $EladasContent;
$Eladasok[$new_array[$ElLoop][EladasKep] . '-' . $new_array[$ElLoop][EladasSzin]] = $EladasContent[EladasQTY];
$ElLoop++;
}
关于php - 通过 join 和/或 union 将两个 MySQL 查询简化为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19068904/
hello1 hello2 hello3 hello4 hello5 hello6
有没有更简短的写法: (apply f (cons a (cons b (cons c d)))) ? 谢谢! (我正在编写一些调用其他函数的辅助函数,这种“模式”似乎经常出现
.NET团队北京时间2024年5月22日已正式发布.NET Aspire ,在博客文章里做了详细的介绍:.NET Aspire 正式发布:简化 .NET 云原生开发 - .NET 博客 (micros
在this dbfiddle demo我有一个 DELETE FROM...WHERE 最后像这样: ...... DELETE FROM data_table WHERE
我有几个 if 语句,如下面的一个。我假设这是一种非常糟糕/长期的编码方式,但不确定我应该做些什么不同的事情。有人有什么建议吗? 谢谢 For a = 1 To Leagues If a =
有什么类似的战术simpl为 Program Fixpoint ? 特别是,如何证明以下无关紧要的陈述? Program Fixpoint bla (n:nat) {measure n} := mat
我使用此代码来跟踪表单上是否有任何更改: $(document).on('input', '.track', function() { var form = $(this); }); 由于这不
我有以下函数,我想用 for 循环来简化它,但不知道该怎么做。任何帮助都感激不尽。基本上,如果字段值为 0 或 null,则我的总值(字段)应为 0,否则,如果字段值从 1 到 1000,则总值变为
我正在尝试对时间字符串执行非常简单的解析 data Time = Time Int Int Int String -- example input: 07:00:00AM timeParser ::
为了使我的代码更具可读性和更简单,我对这段代码绞尽脑汁: var refresh = setInterval(datumTijd, 1000); function datumTijd() { do
这个问题已经有答案了: Check if a variable is in an ad-hoc list of values (8 个回答) 已关闭 9 年前。 只是一个基本的if声明,试图使其更简单
我有一个这样的 if 语句 int val = 1; if (val == 0 || val == 1 || val == 2 || ...); 有没有更简单的方法?例如: int val = 1;
我有一个程序,其中有一些 if 语句,与我将要向您展示的程序类似。我想知道你们是否可以帮助我以任何方式简化这个方程。我之所以问这个问题,是因为在我的 Notepad++ 中,它持续了 443 列,如果
是否可以简化这个 if 语句? 如果是,答案是什么? if (type) { if(NdotL >= 0.0) { color
我有一个包含亚马逊大河的 shapefile。仅 shapefile 就有 37.9 MB,连同属性表高达 42.1 MB。我正在生成所有巴西亚马逊的 PNG 图像,每个 1260x940 像素,sh
System.out.printf("%7s", "a"); System.out.printf("%7s", "b"); System.out.printf("%7s", "c"); S
假设我们有客户端-服务器应用程序,由一个 makefile 编译。服务器使用 libtask 为并行客户端提供服务。客户端使用 ncurses 来处理某些图形。目录树如下所示: ./ --bin/ -
我在 Mono 密码转换的重新实现中找到了这段代码。 我没有修改或简化任何东西 - 这就是它的实际运行方式(有评论如//Dispose unmanaged objects,但实际上什么也没做)。 现在
我需要一些帮助来简化这个包含数百行的庞大代码,但我真的不知道该怎么做。代码看起来真的很乱,我需要的是返回具有预定义文本颜色的模型。有什么简单的方法吗? 我必须多解释一点:- 有一个包含许多型号的手机列
这里有一些代码可以正常工作,但我认为可以简化/缩短。它基本上是点击一个列表项,获取它的 ID,然后根据 ID 显示/隐藏/删除元素。 关于如何使用函数或循环来简化它的建议? $("#btn_remov
我是一名优秀的程序员,十分优秀!