gpt4 book ai didi

i want to display output like this with sql server [closed](我想用SQL SERVER[已关闭]显示如下输出)

转载 作者:bug小助手 更新时间:2023-10-24 17:55:08 26 4
gpt4 key购买 nike




this is my original table in database

这是我数据库中的原始表


name           qty
QMORIASDWAD 1
QMORIASDWAD 3
QMORIASDWAD 4
QMORIASDWAD 5
QMORIASDWAD 6
QMORIASDWAD 7
QMORIASDWAD 8

and i want my reuslt output with select to be like this

我希望我使用SELECT的reuslt输出是这样的


name qty
qm2 1
qm2 3
qm2 4
qm2 5
qm2 6
qm2 7
qm2 8

更多回答

what is the logic here ?

这里的逻辑是什么?

it's just select logic, can i use case clause?

这只是选择逻辑,我可以使用CASE子句吗?

this is my original querry SELECT DISTINCT name, qty FROM db WHERE cast (prod_date AS DATE) = cast (getdate () AS DATE) and name <> 'asd' ORDER BY name,qty

这是我的原始查询SELECT DISTINCT NAME,QTY FROM DB WHERE CAST(PROD_DATE AS DATE)=CAST(getDate()AS DATE)AND NAME<>‘ASD’ORDER BY NAME,QTY

No. We are asking what is the logic to select 'qm2' instead of 'QMORIASDWAD'. Do you just want a constant 'qm2', regardless of what the row contains? Or is it 'qm', because 'QMORIASDWAD' starts with 'QM'? But what would the '2'come from then? What would be the output, if a row didn't have 'QMORIASDWAD', but 'ABCDEFGHIJK' forinstance?

不是的。我们在问,选择‘QM2’而不是‘QMORIASDWAD’的逻辑是什么。您是否只想要一个常量‘QM2’,而不管该行包含什么?或者是‘QM’,因为‘QMORIASDWAD’以‘QM’开头?如果一行没有‘QMORIASDWAD’,而是‘ABCDEFGHIJK’,那么‘2’会从哪里来呢?

SELECT 'qm2' as name, qty FROM MyTable will give you that output. You can try that and come back with some clarification about what you really want.

选择‘QM2’作为名称,MyTable中的数量将为您提供该输出。你可以试一试,然后回来澄清一下你真正想要的是什么。

优秀答案推荐

your data

您的数据


CREATE TABLE yourtable(
name VARCHAR(100) NOT NULL
,qty INTEGER NOT NULL
);
INSERT INTO yourtable(name,qty) VALUES
('QMORIASDWAD',1),
('QMORIASDWAD',3),
('QMORIASDWAD',4),
('QMORIASDWAD',5),
('QMORIASDWAD',6),
('QMORIASDWAD',7),
('QMORIASDWAD',8);

Just use Concat,Lower and Left function

只需使用Concat、Low和Left函数


SELECT 
CONCAT(LOWER(left(name,2)),2) name,
qty
FROM YourTable

dbfiddle

数据库小提琴


Based on your query,you can use with

根据您的查询,您可以使用


with t as (
SELECT
DISTINCT name,
qty
FROM
db
WHERE
cast (prod_date AS DATE) = cast (
getdate () AS DATE
)
and name <> 'asd'
)

SELECT
CONCAT (LOWER(left(NAME, 2)),2) NAME
,qty
FROM t

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com