简体   繁体   English

仅在数据库查询时的名字和姓氏首字母

[英]first name and last name initial only on Database query

Hi can you help me in my problem? 嗨,您能帮我解决我的问题吗?

I want to create a Profile Name which only read like this Sergio E. not this Sergio Encabo 我想创建一个配置文件名称,其名称只能像这样的Sergio E.读,而不是这样的Sergio Encabo

Here is the query I have 这是我的查询

SELECT p.id, p.title, COUNT(b.id) AS bids, p.slug, p.`description`, p.budget AS budget, p.`isFeatured`, p.`slug`, u.`profileLink`, u.`profilePhoto`, CONCAT_WS(' ', u.firstName , u.lastName ) AS fullName 
FROM tbl_projects AS p 
LEFT JOIN tbl_users AS u ON p.userId = u.userId 
LEFT JOIN tbl_bids AS b ON p.`id` = b.`projectId` 
WHERE p.`isActive` = 'y' AND u.`isActive` = 'y' AND p.`jobStatus` = 'open' AND p.userId=? 
GROUP BY p.id 
ORDER BY p.`id` DESC 

You could use the first char on left for lastname 您可以使用左侧的第一个字符作为姓氏

but you should not use left joined tables columns in where condition this work as inner join 但您不应该在这种情况下将左联接表列用作内部联接
add these condition to on clause 将这些条件添加到on子句

    $qry = "SELECT p.id
        , p.title
        , COUNT(b.id) AS bids
        , p.slug
        , p.`description`
        , p.budget AS budget
        , p.`isFeatured`
        , p.`slug`
        , u.`profileLink`
        , u.`profilePhoto`
        , CONCAT( u.firstName ,' ', left(u.lastName,1), '.' ) AS fullName 
        FROM tbl_projects AS p 
        LEFT JOIN tbl_users AS u ON p.userId = u.userId   AND u.`isActive` = 'y' 
        LEFT JOIN tbl_bids AS b ON p.`id` = b.`projectId`
        WHERE p.`isActive` = 'y' 
        AND p.`jobStatus` = 'open' 
         AND p.userId=? 
         GROUP BY p.id 
         ORDER BY p.`id` DESC  ";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM