我有一个表中的数据,其中有“买入”和“卖出”和数量。我想要查询,以便如果它等于“卖出”,我将数量列乘以负数。到目前为止,我只是选择数据并从某个时间范围内获取。没什么复杂的。
我有更新到数据库表的方法,但是当我调用它时,我有一个异常"语法不正确'('."
这是方法
internal Boolean update(int customerID,int followingID, string fullName, string idNumber, string address, string tel, string mobile1, string mobile2, string email, string customerComment, DateTime timeStamp)
{
string sqlStatment = "update customers set (followingID, fullName,idNumber,address,tel,mobile1,mobile2,email,customerComment,timeStamp) = (@followingID, @fullName,@idNumber,@address,@tel,@mobile1,@mobile2,@email,@customerComment,@timeStamp) where customerID=@customerID";
SqlConnection con = new SqlConnection();
con.ConnectionString = connection;
SqlCommand cmd = new SqlCommand(sqlStatment, con);
cmd.Parameters.AddWithValue("@customerID", customerID);
cmd.Parameters.AddWithValue("@followingID", followingID);
cmd.Parameters.AddWithValue("@fullName", fullName);
cmd.Parameters.AddWithValue("@idNumber", idNumber);
cmd.Parameters.AddWithValue("@address", address);
cmd.Parameters.AddWithValue("@tel", tel);
cmd.Parameters.AddWithValue("@mobile1", mobile1);
cmd.Parameters.AddWithValue("@mobile2", mobile2);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@customerComment", customerComment);
cmd.Parameters.AddWithValue("@timeStamp", timeStamp);
bool success = false;
try …Run Code Online (Sandbox Code Playgroud) SQL where子句在我的数据库中不起作用.
我有一个名为"网站"的表和类似的结构
id site
1 xyz.com
2 google.com
3 example.com
Run Code Online (Sandbox Code Playgroud)
我正在运行此SQL查询
SELECT * FROM `sites` WHERE `site` = "google.com";
Run Code Online (Sandbox Code Playgroud)
但我得到了这个输出
MySQL returned an empty result set (i.e. zero rows). (Query took 0.0009 sec)
Run Code Online (Sandbox Code Playgroud)
我以前从未见过这样的生活.
更新:截图
我不想在项目中应用此查询.
SELECT * FROM `sites` WHERE `site` LIKE "%google.com%";
Run Code Online (Sandbox Code Playgroud)

#
Run Code Online (Sandbox Code Playgroud)

真正的问题在于insert创建DB的命令.尝试
INSERT INTO sites (id, site) VALUES (1, '\nxyz.com\n'), (2, '\ngoogle.com\n'), (3, '\nexample.com\n')
Run Code Online (Sandbox Code Playgroud)
并手动检查表中的记录.你不会看到换行符.这是我注意到的SQL中的一个问题.
我有一个SQL查询,如下所示:
SELECT name FROM sessions WHERE name ILIKE 'org_name.%';
Run Code Online (Sandbox Code Playgroud)
但我真的有兴趣用格式字符串(%s)替换'org_name'.
我试图做这样的事情:
query := fmt.Sprintf("SELECT name FROM sessions WHERE name ILIKE '%s.%'", "org_name2")
Run Code Online (Sandbox Code Playgroud)
但似乎不喜欢它,因为写'%'作为格式字符串无效.
我知道我可以通过这种方式解决它:
orgName := "org_name2"
condition := fmt.Sprintf("%s", orgName) + ".%"
query := fmt.Sprintf("SELECT name FROM sessions WHERE name ILIKE '%s'", condition)
Run Code Online (Sandbox Code Playgroud)
但是,我宁愿不这样做,因为这里的变量只是org_name.
这有解决方案吗?
谢谢!