- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在连接数据库中的两个表。但我在显示第二个表中的数据时遇到问题。
我的第一个表包含具有多个itemcode的数据,但我想在页面中显示一次,因此在查询中使用了GROUP BY。在我的第二个表上也有多个 itemcode 但这次我想在页面上显示数据。但它没有显示,是因为 GROUP BY 的原因吗?您能帮我确定查询中有什么问题吗?谢谢。
这是我想要的示例表。
这是我的查询(**我简化了它):
SELECT mcc.ALL, mva.ALL
FROM `mtrl_cons_cost` mcc
LEFT JOIN material_value_aging mva ON mcc.itemcode = mva.item_code
GROUP BY mcc.site_cons , mcc.itemcode, mcc.deptcode , mcc.item_desc, mcc.subinv_code , mcc.item_uom
更新这是整个代码。请参阅。
$site = "112";
$date1 = date("Y-m");
$date2 = date("Y-m", strtotime("-1 month") ) ;
$date3 = date("Y-m", strtotime("-2 month") ) ;
$date1s = date("Ym");
$date2s = date("Ym", strtotime("-1 month") ) ;
$date3s = date("Ym", strtotime("-2 month") ) ;
echo "<form>";
echo "<h2>CONSUMPTION REPORT AND MATERIAL VALUE AGING AS OF $date1</h2>";
echo "<table border=5>";
echo "<tr class=header bgcolor=#adff2f rowspan=2>";
echo "<th>SITE</th>";
echo "<th>DEPT</th>";
echo "<th>ITEM CODE</th>";
echo "<th>DESCRIPTION</th>";
echo "<th>ITEM TYPE</th>";
echo "<th>UOM</th>";
echo "<th>{$date1} QUANTITY</th>";
echo "<th>{$date1} COST</th>";
echo "<th>{$date2} QUANTITY</th>";
echo "<th>{$date2} COST</th>";
echo "<th>{$date3} QUANTITY</th>";
echo "<th>{$date3} COST</th>";
echo "<th bgcolor=yellow></th>";
/*** Material Value Aging ***/
//echo "<th>SITE</th>";
echo "<th>CUSTOMER PN</th>";
//echo "<th>ITEM CODE</th>";
echo "<th>TYPE</th>";
echo "<th>UOM</th>";
echo "<th>DESCRIPTION</th>";
//echo "<th>DEPT CODE</th>";
echo "<th>SUB</th>";
echo "<th>RECEIVED DATE</th>";
echo "<th>AGE</th>";
echo "<th>LOT SERIAL</th>";
echo "<th>QUANTITY</th>";
echo "<th>VALUE IN USD</th>";
echo "<th>A30 0-30DAYS</th>";
echo "<th>A60 31-60DAYS</th>";
echo "<th>A90 61-90DAYS</th>";
echo "<th>A120 91-120DAYS</th>";
echo "<th>A180 121-180DAYS</th>";
echo "<th>ABOVE 180 DAYS</th>";
echo "</tr>";
$query="
SELECT mcc.site_cons , mcc.deptcode , mcc.itemcode , mcc.item_desc , mcc.subinv_code , mcc.item_uom , SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date1'
THEN mcc.qty
END ) AS 'qty_$date1', SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date1s'
THEN mcc.total_cost
END ) AS 'tot_cost_$date1s', SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date2'
THEN mcc.qty
END ) AS 'qty_$date2', SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date2s'
THEN mcc.total_cost
END ) AS 'tot_cost_$date2s', SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date3'
THEN mcc.qty
END ) AS 'qty_$date3', SUM(
CASE WHEN DATE_FORMAT( mcc.trans_date , '%Y-%m' ) = '$date3s'
THEN mcc.total_cost
END ) AS 'tot_cost_$date3s', mva.*
FROM `mtrl_cons_cost` mcc
LEFT JOIN material_value_aging mva ON mcc.itemcode = mva.item_code
WHERE mcc.site_cons LIKE '$site'
GROUP BY mcc.site_cons , mcc.itemcode, mcc.deptcode , mcc.item_desc, mcc.subinv_code , mcc.item_uom
";
//
$conn = dbConnect();
$stmt = $conn->prepare($query);
$stmt-> execute();
while($getrow=$stmt->fetch(PDO::FETCH_ASSOC)) {
$site_cr = $getrow['site_cons'];
$deptcode_cr = $getrow['deptcode'];
$itemcode_cr = $getrow['itemcode'];
$itemdesc_cr = $getrow['item_desc'];
$subinvcode_cr = $getrow['subinv_code'];
$itemuom_cr = $getrow['item_uom'];
$qtydate1s_cr = $getrow['qty_$date1s'];
$costdate1s_cr = $getrow['tot_cost_$date1s'];
$qtydate2s_cr = $getrow['qty_$date2s'];
$costdate2s_cr = $getrow['tot_cost_$date2s'];
$qtydate3s_cr = $getrow['qty_$date3s'];
$costdate3s_cr = $getrow['tot_cost_$date3s'];
$sitec = $getrow['site'];
$cust_pn = $getrow['customer_pn'];
$itemcode = $getrow['item_code'];
$itemtype = $getrow['item_type'];
$UOM = $getrow['uom'];
$desc = $getrow['description'];
$deptcode = $getrow['dept_code'];
$subcode = $getrow['subinventory_code'];
$received_Date = $getrow['received_date'];
$age = $getrow['age'];
$lot_no = $getrow['lot_number'];
$qty = $getrow['qty'];
$ttl_val = $getrow['ttl_value'];
echo "<tr>";
echo "<td>{$site_cr}</td>";
echo "<td>{$deptcode_cr}</td>";
echo "<td>{$itemcode_cr}</td>";
echo "<td>{$itemdesc_cr}</td>";
echo "<td>{$subinvcode_cr}</td>";
echo "<td>{$itemuom_cr}</td>";
echo "<td>{$qtydate1s_cr}</td>";
echo "<td>{$costdate1s_cr}</td>";
echo "<td>{$qtydate2s_cr}</td>";
echo "<td>{$costdate2s_cr}</td>";
echo "<td>{$qtydate3s_cr}</td>";
echo "<td>{$costdate3s_cr}</td>";
echo "<td bgcolor=yellow> </td>";
//echo "<td>{$sitec}</td>";
echo "<td>{$cust_pn}</td>";
//echo "<td>{$itemcode}</td>";
echo "<td>{$itemtype}</td>";
echo "<td>{$UOM}</td>";
echo "<td>{$desc}</td>";
//echo "<td>{$deptcode}</td>";
echo "<td>{$subcode}</td>";
echo "<td>{$received_Date}</td>";
echo "<td>{$age}</td>";
echo "<td>{$lot_no}</td>";
echo "<td>{$qty}</td>";
echo "<td>{$ttl_val}</td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td> </td>";
echo "</tr>";
}
$conn=null;
echo "</table>";
echo "</form>";
表 1:mtrl_cons_cost
CREATE TABLE IF NOT EXISTS `mtrl_cons_cost` (
`site_cons` int(11) NOT NULL,
`deptcode` int(11) NOT NULL,
`trans_date` date NOT NULL,
`itemcode` varchar(15) NOT NULL,
`item_desc` varchar(500) NOT NULL,
`subinv_code` varchar(20) NOT NULL,
`item_uom` varchar(50) NOT NULL,
`unit_price` decimal(20,6) NOT NULL,
`qty` decimal(20,6) NOT NULL,
`total_cost` decimal(20,6) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
表 2: Material 值老化
CREATE TABLE IF NOT EXISTS `material_value_aging` (
`site` varchar(10) NOT NULL,
`customer_pn` varchar(50) NOT NULL,
`item_code` varchar(50) NOT NULL,
`item_type` varchar(10) NOT NULL,
`uom` varchar(10) NOT NULL,
`description` varchar(100) NOT NULL,
`dept_code` int(11) NOT NULL,
`subinventory_code` varchar(10) NOT NULL,
`received_date` date NOT NULL,
`age` int(11) NOT NULL,
`lot_number` varchar(100) NOT NULL,
`qty` decimal(10,2) NOT NULL,
`ttl_value` decimal(10,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
最佳答案
如果您执行GROUP BY my_columns
,则每个列值组合将只有一行。所有其他选定的列(不在 GROUP BY
中的列)都是从每个组的随机行中选择的(也许是第一个,我不记得了)。这里的 LEFT OUTER JOIN
允许行根本没有 mva
列。
GROUP BY
用于处理聚合,例如 COUNT
、SUM
或 MAX
。只需删除 GROUP BY
并使用 ORDER BY
即可。您将获得经过良好排序的行 - 左侧有重复信息 - 您只需迭代排序结果即可迭代地识别您的组。
SELECT mcc.ALL, mva.ALL
FROM `mtrl_cons_cost` mcc
LEFT JOIN material_value_aging mva ON mcc.itemcode = mva.item_code
ORDER BY mcc.site_cons , mcc.itemcode, mcc.deptcode , mcc.item_desc, mcc.subinv_code , mcc.item_uom
关于mysql - SQL 两个表的左连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35357949/
我知道这个问题可能已经被问过,但我检查了所有这些,我认为我的情况有所不同(请友善)。所以我有两个数据集,第一个是测试数据集,第二个是我保存在数据框中的预测(预测值,这就是没有数据列的原因)。我想合并两
在 .loc 方法的帮助下,我根据同一数据框中另一列中的值来识别 Panda 数据框中某一列中的值。 下面给出了代码片段供您引用: var1 = output_df['Player'].loc[out
当我在 Windows 中使用 WinSCP 通过 Ubuntu 连接到 VMware 时,它提示: The server rejected SFTP connection, but it lis
我正在开发一个使用 xml web 服务的 android 应用程序。在 wi-fi 网络中连接时工作正常,但在 3G 网络中连接时失败(未找到 http 404)。 这不仅仅发生在设备中。为了进行测
我有一个XIB包含我的控件的文件,加载到 Interface Builder(Snow Leopard 上的 Xcode 4.0.2)中。 文件的所有者被设置为 someClassController
我在本地计算机上管理 MySQL 数据库,并通过运行以下程序通过 C 连接到它: #include #include #include int main(int argc, char** arg
我不知道为什么每次有人访问我网站上的页面时,都会打开一个与数据库的新连接。最终我到达了大约 300 并收到错误并且页面不再加载。我认为它应该工作的方式是,我将 maxIdle 设置为 30,这意味着
希望清理 NMEA GPS 中的 .txt 文件。我当前的代码如下。 deletes = ['$GPGGA', '$GPGSA', '$GPGSV', '$PSRF156', ] searchquer
我有一个 URL、一个用户名和一个密码。我想在 C# .Net WinForms 中建立 VPN 连接。 你能告诉我从哪里开始吗?任何第三方 API? 代码示例将受到高度赞赏... 最佳答案 您可以像
有没有更好的方法将字符串 vector 转换为字符 vector ,字符串之间的终止符为零。 因此,如果我有一个包含以下字符串的 vector "test","my","string",那么我想接收一
我正在编写一个库,它不断检查 android 设备的连接,并在设备连接、断开连接或互联网连接变慢时给出回调。 https://github.com/muddassir235/connection_ch
我的操作系统:Centos 7 + CLOUDLINUX 7.7当我尝试从服务器登录Mysql时 [root@server3 ~]# Mysql -u root -h localhost -P 330
我收到错误:Puma 发现此错误:无法打开到本地主机的 TCP 连接:9200(连接被拒绝 - 连接(2)用于“本地主机”端口 9200)(Faraday::ConnectionFailed)在我的
请给我一些解决以下错误的方法。 这是一个聊天应用....代码和错误如下:: conversations_controller.rb def create if Conversation.bet
我想将两个单元格中的数据连接到一个单元格中。我还想只组合那些具有相同 ID 的单元格。 任务 ID 名称 4355.2 参与者 4355.2 领袖 4462.1 在线 4462.1 快速 4597.1
我经常需要连接 TSQL 中的字段... 使用“+”运算符时 TSQL 强制您处理的两个问题是 Data Type Precedence和 NULL 值。 使用数据类型优先级,问题是转换错误。 1)
有没有在 iPad 或 iPhone 应用程序中使用 Facebook 连接。 这个想法是登录这个应用程序,然后能够看到我的哪些 facebook 用户也在使用该应用程序及其功能。 最佳答案 是的。
我在连接或打印字符串时遇到了一个奇怪的问题。我有一个 char * ,可以将其设置为字符串文字的几个值之一。 char *myStrLiteral = NULL; ... if(blah) myS
对于以下数据 - let $x := "Yahooooo !!!! Select one number - " let $y := 1 2 3 4 5 6 7 我想得到
我正在看 UDEMY for perl 的培训视频,但是视频不清晰,看起来有错误。 培训展示了如何使用以下示例连接 2 个字符串: #!usr/bin/perl print $str = "Hi";
我是一名优秀的程序员,十分优秀!