s_id 主键
g_id 产品id
r_id 1000 代表口味
r_id 1004 代表产地
s_cname 中文
s_ename 英文
s_kname 繁体中文
s_level 是否删除 2为正常
s_date 添加日期
解决方案 »
- 请教一个SQL语句~~
- 我的Log Explorer怎么附加不上日志文件啊,大俠來幫幫我!
- 怎样用select语句选取表中的任意一条记录号为N的记录
- 求助三表连接join的用法?请大虾修正我的错误!
- sql中比较字符串时,发现'A'与'a'是相等的.即'A'='a'为真,如何实现为假呀?
- 如何用T-SQL将16进制转换成字符串?(内附微软技术人员的解答)
- 一日期字段,怎么样取得该字段的的小时和分钟,想得到( hour*60 + minutes)结果,该怎么写表达式?
- 对我而言比较难的一个查询语句,请高手解决,一定解决呀!!!!!
- 求一sql语句,大家来帮忙
- 关于建表问题?
- 十万火急!!!!sqlserver数据库数据恢复问题
- 如何批量修改查询出来的表的字段名
还有为什么你最后要的结果 应该是 1002,1003 are you sure?
g_id 产品id
r_id 1000 代表口味
r_id 1004 代表产地
s_cname 中文
s_ename 英文
s_kname 繁体中文
s_level 是否删除 2为正常
s_date 添加日期
还有为什么你最后要的结果 应该是 1002,1003 are you sure?因为满足第一个语句的条件的有 1002 1003 1004
满足第二个语句的条件的有 1003 1002
同事满足两个语句条件的 按道理来说应该只有 1003 1002
from (select g_id from spec where s_cname='深度' and r_id='1000') a
join (select g_id from spec where s_cname='巴西' and r_id='1004') b
on a.g_id = b.g_id
select g_id from spec where g_id in
(select g_id from spec where s_cname='深度' and r_id='1000')
and g_id in
(select g_id from spec where s_cname='巴西' and r_id='1004')你的这句:
select g_id from spec where (s_cname='深度' and r_id='1000') and (s_cname='巴西' and r_id='1004')
改一下Where的顺序,就如下:
select g_id from spec where (s_cname='深度' and s_cname='巴西') and (r_id='1000' and r_id='1004')
返回的结果肯定是空的。
SELECT A.g_id FROM spec A
WHERE EXISTS(SELECT 1 FROM spec B WHERE A.g_id=B.g_id B.s_cname='深度' and B.r_id='1000')
AND EXISTS(SELECT 1 FROM spec C WHERE A.g_id=C.g_id C.s_cname='巴西' and C.r_id='1004')
GROUP BY A.g_id
这个语句就查询不出来啊,表内s_cname='深度'同时还要='巴西' ,数据表里就没有这种的数据,
select a.g_id from (select g_id from spec where s_cname='深度' and r_id='1000') a inner
join (select g_id from spec where s_cname='巴西' and r_id='1004') b
on a.g_id = b.g_id
肯定为空啊。不存在记录同时满足s_cname='深度' and s_cname='巴西'
select g_id from spec t where t.s_cname='深度' and t.r_id='1000' and
exists(select 1 from spec where g_id=t.g_id and s_cname='巴西' and r_id='1004')