尝试将货币符号添加到MySQL

发布于 2024-11-26 12:06:20 字数 2513 浏览 1 评论 0原文

我有以下 SQL 查询:

SELECT mshipType_Name,
       COUNT('x') AS mshipssold,
       sum(memberToMship_InductionFee+memberToMship_JoinFee+
           (IF(mshipOption_Period='year',
             TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
             TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod)) as value
FROM membertomships
  INNER JOIN mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
  INNER JOIN mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
GROUP BY mshipType_Name;

它将显示这样的结果:

            mshiptype_name       mshipsold       value
            --------------       ---------       -----
            gold                 3               3800.00
            silver               4               4800.00

很好,我可以得到这样的结果,井号符号已添加值:

            mshiptype_name       mshipsold       value
            --------------       ---------       -----
            gold                 3               £ 3800.00
            silver               4               £ 4800.00

Is it possible with a MySQL query?

修改后的查询:

         SELECT  set names utf-8,mshipType_Name, COUNT('x') AS mshipssold,
                               CONCAT('£', sum(memberToMship_InductionFee+memberToMship_JoinFee+
                                  (IF(mshipOption_Period='year',
                                  TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
                                  TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod))) as value
                              FROM membertomships
                              inner join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
                              inner join mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
                              WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
                              GROUP BY mshipType_Name;





  Error Code: 1064
       You have an error in your SQL syntax; check the manual that corresponds to your       MySQL server version for the right syntax to use near 'set names utf-8,mshipType_Name, COUNT('x') AS mshipssold,
                  ' at line 1

I have the following SQL query:

SELECT mshipType_Name,
       COUNT('x') AS mshipssold,
       sum(memberToMship_InductionFee+memberToMship_JoinFee+
           (IF(mshipOption_Period='year',
             TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
             TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod)) as value
FROM membertomships
  INNER JOIN mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
  INNER JOIN mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
GROUP BY mshipType_Name;

It will show the results like this:

            mshiptype_name       mshipsold       value
            --------------       ---------       -----
            gold                 3               3800.00
            silver               4               4800.00

Its fine can I get the results like this with pound symbol has added in value:

            mshiptype_name       mshipsold       value
            --------------       ---------       -----
            gold                 3               £ 3800.00
            silver               4               £ 4800.00

Is it possible with a MySQL query?

MODIFIED QUERY :

         SELECT  set names utf-8,mshipType_Name, COUNT('x') AS mshipssold,
                               CONCAT('£', sum(memberToMship_InductionFee+memberToMship_JoinFee+
                                  (IF(mshipOption_Period='year',
                                  TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
                                  TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod))) as value
                              FROM membertomships
                              inner join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
                              inner join mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
                              WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
                              GROUP BY mshipType_Name;





  Error Code: 1064
       You have an error in your SQL syntax; check the manual that corresponds to your       MySQL server version for the right syntax to use near 'set names utf-8,mshipType_Name, COUNT('x') AS mshipssold,
                  ' at line 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2024-12-03 12:06:20

是的,尝试使用:

set names utf8;
SELECT mshipType_Name, COUNT('x') AS mshipssold,
                                sum(memberToMship_InductionFee+memberToMship_JoinFee+
                                  (IF(mshipOption_Period='year',
                                  TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
                                  CONCAT('£ ', TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod)) ) as value
                              FROM membertomships
                              inner join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
                              inner join mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
                              WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
                              GROUP BY mshipType_Name;

Yes, try with:

set names utf8;
SELECT mshipType_Name, COUNT('x') AS mshipssold,
                                sum(memberToMship_InductionFee+memberToMship_JoinFee+
                                  (IF(mshipOption_Period='year',
                                  TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate),
                                  CONCAT('£ ', TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod)) ) as value
                              FROM membertomships
                              inner join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
                              inner join mshiptypes on mshipoptions.mshipType_Id = mshiptypes.mshipType_Id
                              WHERE memberToMship_StartDate BETWEEN '2011-06-26' AND '2011-07-26'
                              GROUP BY mshipType_Name;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文