小编Dav*_*sty的帖子

MYSQL查询 - 使用格式但不使用逗号

我试图在SQL查询中使用格式以适应报告包.我有数字,我需要显示为两位小数的货币,所以我使用format命令来做到这一点.问题是格式也用逗号分隔数千,报告包求和函数无法处理,因此将格式化的数值视为文本而不添加.查询使用: -

SELECT customers.name AS "customers name", FORMAT(contracts.charge,2) AS "contracts charge" 
FROM customers
ORDER BY customers.name
Run Code Online (Sandbox Code Playgroud)

(实际查询要复杂得多,但这是相关部分)

为了更全面地解释: -

如果数值为123.1,则格式化的输出为123.10.如果数值为1234.1,则格式化输出为1,234.10,而不是

我需要找到一种方法来说服查询输出1234.10

非常感谢

mysql format comma

9
推荐指数
2
解决办法
2万
查看次数

创建制表符分隔文件

我正在尝试创建一个制表符分隔文件输出,我可以用它来加载到quickbooks.我在标题上使用以下代码.

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=\"my-data.txt\"");
Run Code Online (Sandbox Code Playgroud)

我有两个问题.

第一个是一些内容是文本但其中有一个逗号,(这就是我使用制表符分隔的原因.SQL(善意)为我放置了""这些字段,然后转移到文本文件,然后随后进入帐户包.我无法看到我如何阻止SQL这样做或如何从文本文件的内容中删除它.

其次,脚本中的第一个输出是一个echo语句,后跟一个tab等; 然而,实际输出在开头包含一个额外的行(我可以看到已经插入了ASCII 0A)我无法看到它来自哪里?

我附上了我正在使用的代码,以防我遗漏了一些明显的东西.

救命

非常感谢

<?php
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=\"my-data.txt\"");
// Open standard includes 
include ('./includes/protect.php');  //User name and password control
require_once('Connections/Dragonnet.php');
mysql_select_db($database_Dragonnet, $Dragonnet);  //Connect to database
?>

<?php

$batch1 =  $_GET["batch1"];
$batch2 =  $_GET["batch2"];
$query =  "SELECT invtrans.StdInvNar1 AS 'invtrans StdInvNar1',
                  invtrans.StdInvNar2 AS 'invtrans StdInvNar2',
                  invtrans.StdInvNar3 AS 'invtrans StdInvNar3',
                  invtrans.StdInvNar4 AS 'invtrans StdInvNar4',
                  invtrans.StdInvNar5 AS 'invtrans StdInvNar5',
                  invtrans.StdInvNar6 AS 'invtrans StdInvNar6',
                  invtrans.StdInvNar7 AS 'invtrans StdInvNar7',
                  invtrans.StdInvNar8 AS …
Run Code Online (Sandbox Code Playgroud)

php database

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

comma ×1

database ×1

format ×1

mysql ×1

php ×1