我有这样的查询:
SELECT
Count(*)
, Location_tbl.LocName as Location
, Status_tbl.Status_Name
FROM
Transaction_tbl
LEFT JOIN
Location_tbl ON Transaction_tbl.Locid = Location_tbl.Locid
LEFT JOIN
Status_tbl ON Transaction_tbl.Status = Status_tbl.Status
WHERE
Transaction_tbl.Status='3' and
Transaction_tbl.Locid IN (5) and
DATEDIFF(n, Transaction_tbl.Paydate, GETDATE()) > 10
GROUP BY
Location_tbl.LocName, Status_tbl.Status_Name
我这样出去了:
car_count Location Status_Name
25 fashion requested
我想设置status_Name
始终:违规请求..我该怎么做?在我的status
表中没有违反请求的任何状态..
答案 0 :(得分:3)
您可以将字符串文字指定为列,但我不确定您何时可以从业务逻辑或显示层执行此操作:
SELECT
Count(*)
, Location_tbl.LocName as Location
, 'Violated Request' AS Status_Name
FROM
Transaction_tbl
LEFT JOIN
Location_tbl ON Transaction_tbl.Locid = Location_tbl.Locid
LEFT JOIN
Status_tbl ON Transaction_tbl.Status = Status_tbl.Status
WHERE
Transaction_tbl.Status='3' and
Transaction_tbl.Locid IN (5) and
DATEDIFF(n, Transaction_tbl.Paydate, GETDATE()) > 10
GROUP BY
Location_tbl.LocName, Status_tbl.Status_Name