SQL-将字符串连接到参数($1)

SQL-将字符串连接到参数($1),sql,Sql,第一次在网站上发布,所以我希望我不会违反任何规则,有人可以帮助我 我有下表: machine_name variable_name variable_value machine1 WAV 56789 machine1 WAV_CONT 5 machine1 AVI 67890 machine1 AVI_CONT 3 machine2

第一次在网站上发布,所以我希望我不会违反任何规则,有人可以帮助我

我有下表:

machine_name    variable_name    variable_value
machine1        WAV              56789
machine1        WAV_CONT         5
machine1        AVI              67890
machine1        AVI_CONT         3
machine2        WAV              786579
machine2        WAV_CONT         20
machine2        AVI              182641
machine2        AVI_CONT         9
我使用的参数是$1。我想创建一个查询,给出以下结果 当用户输入wav时:

machine_name    variable_name     space       count
machine1        WAV               56789       5
machine2        WAV               786579      20
或者,当用户输入AVI时,会出现另一个结果

machine_name    variable_name     space       count
machine1        AVI               67890       3
machine2        AVI               182641      9
两个字段都可以使用一个参数吗?我的意思是,有没有一种方法可以将$1连接到字符串_CONT,这样用户只需要输入WAV或AVI就可以得到上面的任何结果


谢谢

我想在表中添加一个新的字段,标记为Type。然后可以使用WAV或AVI进行过滤

如果您只需要查询:

declare @param varchar(10)
set @param = 'WAV'

Select * from YOUR_TABLE where variable_name = @param

你可以用穷人的支点:

select
  machine_name,
  @param as variable_name,
  -- Turn rows into columns:
  -- These expressions are zero for the rows we don't want.
  sum(case when variable_name like '%_CONT' then 0 else variable_name end) as space,
  sum(case when not variable_name like '%_CONT' then 0 else variable_name end) as count
from TABLE_NAME
group by machine_name

你不应该考虑换一下桌子吗?
select
  machine_name,
  @param as variable_name,
  -- Turn rows into columns:
  -- These expressions are zero for the rows we don't want.
  sum(case when variable_name like '%_CONT' then 0 else variable_name end) as space,
  sum(case when not variable_name like '%_CONT' then 0 else variable_name end) as count
from TABLE_NAME
group by machine_name