美元符号逗号逗号

时间:2018-10-31 12:41:03

标签: sql

我有这段代码来获取总计和其他字段。我感兴趣的是 要获得带有$符号,逗号和02小数位的总值,将是 涵盖所有这些的最佳功能。 因此总金额应为:$ 1,780.00

请告知

select distinct
    c.givenname, c.familyname, s.total, p.title,
    a.givenname+' '+a.familyname as artist
from
    customers as c
        join sales as s on c.id=s.customerid
        join saleitems as si on s.id=si.saleid  
        join paintings as p on si.paintingid=p.id   
        join artists as a on p.artistid=a.id;

我得到的结果是这样的:

Aloysius Peace  1780.0000 Woman in Black (Femme en noir)Mary Cassatt
Amanda  Lynn    1115.0000 Le Moulin de la Galette   Pierre-Auguste Renoir
Amanda  Lynn    1115.0000 Madamoiselle RiviereJean-Auguste-Dominique Ingres
Amanda  Lynn    1115.0000 Pollard Willows With SETting SunVincent Van Gogh
Amelia  Rate    2125.0000 Flowers in a Vase with Shells and InseBalthasar Van 
Amelia  Rate    2125.0000 The Meeting of St Anthony Abbot and St Paul in the 
Amelia  Rate    2125.0000 The Two Girlfriends   Henri de Toulouse-Lautrec
Amelia  Rate    2125.0000 Vision After the Sermon, Jacob Wrestling  

1 个答案:

答案 0 :(得分:0)

在您的代码中使用类似的内容。 (对于MS SQL)

select '$' + cast(cast (s.total as decimal (9,2)) as varchar(20)) as price