我有以下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
很好,我可以得到这样的结果,而pound符号已经增加了价值:
mshiptype_name mshipsold value
-------------- --------- -----
gold 3 £ 3800.00
silver 4 £ 4800.00
是否可以使用MySQL查询?
修改过的查询:
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
答案 0 :(得分:0)
是的,请尝试:
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;