g_id Descending ga_id ga_gid ga_ca_id ga_value
58698 51 58698 207 b
58698 50 58698 207 a
58698 49 58698 178 blue
58698 48 58698 178 red
58697 NULL NULL NULL NULL
58690 39 58690 207 000
58690 38 58690 178 blue
58689 5 58689 178 red
58689 6 58689 178 green
58689 7 58689 207 属性5
要结果:
g_id 即符合ga_id207=a又ga_id178=red
以上表只有58698符合高手求助?????
58698 51 58698 207 b
58698 50 58698 207 a
58698 49 58698 178 blue
58698 48 58698 178 red
58697 NULL NULL NULL NULL
58690 39 58690 207 000
58690 38 58690 178 blue
58689 5 58689 178 red
58689 6 58689 178 green
58689 7 58689 207 属性5
要结果:
g_id 即符合ga_id207=a又ga_id178=red
以上表只有58698符合高手求助?????
解决方案 »
- 在Win 2008 64位上如何彻底删除MySQL
- 求MySql新建表语句
- 6/15 varchar 能否轉成日期型 date 06-15
- 【mysql问题】返回结果集存储在哪里????急急急~~~~~~~~~
- mysql触发器
- Linux下如何开启Mysql的更新日志?
- 怎么在51上执行mysql啊 。。。
- 大家帮我看看,着个句子在那里错了啊?
- 为什么从一个数据库中读取图片然后再写到另一个数据库中老是不成功,但也不显示出错?(SQL server to MySQL))
- 多表查询的写法,各表之间有外键约束
- 外键约束求助
- 返回的sting[]数组 数据为欧泊来-2... 截取'-'左右的文字和数字 怎么绑定到repeater
SELECT g_id from tth a where ga_gid='207' and ga_ca_id='a'
and exists(select 1 from tth where a.ga_id=ga_id and ga_gid='178' and ga_ca_id='red')
from table1 a inner join table1 b on a.g_id=b.g_id
where a.ga_id=207 and b.ga_id=178
and a.ga_value='a' and b.ga_value='red'
SELECT g.g_id, ga. *
FROM goods_chs AS g
LEFT JOIN goods_attribute AS ga ON ( ga.ga_gid = g.g_id )难道我的错???
你的方法看起来很清晰,可还是没调出来
select a.ga_id
from goods_attribute a where a.ga_ca_id='178' and a.ga_value='red'
and exists(select b.ga_id
from goods_attribute b where a.ga_id=b.ga_id and b.ga_ca_id='207' and b.ga_value='a')
+------+-------+------------+-------+--------+----------+----------+
| ID | g_id | Descending | ga_id | ga_gid | ga_ca_id | ga_value |
+------+-------+------------+-------+--------+----------+----------+
| 1 | 58698 | 51 | 58698 | 207 | b | NULL |
| 2 | 58698 | 50 | 58698 | 207 | a | NULL |
| 3 | 58698 | 49 | 58698 | 178 | blue | NULL |
| 4 | 58698 | 48 | 58698 | 178 | red | NULL |
| 5 | 58697 | NULL | NULL | NULL | NULL | NULL |
| 6 | 58690 | 39 | 58690 | 207 | 000 | NULL |
| 7 | 58690 | 38 | 58690 | 178 | blue | NULL |
| 8 | 58689 | 5 | 58689 | 178 | red | NULL |
| 9 | 58689 | 6 | 58689 | 178 | green | NULL |
| 10 | 58689 | 7 | 58689 | 207 | 灞炴€? | NULL |
+------+-------+------------+-------+--------+----------+----------+
10 rows in set (0.00 sec)mysql> SELECT g_id from tth1 a where ga_gid='207' and ga_ca_id='a'
-> and exists(select 1 from tth1 where a.ga_id=ga_id and ga_gid='178' and ga
_ca_id='red');
+-------+
| g_id |
+-------+
| 58698 |
+-------+
1 row in set (0.00 sec)mysql>
select a.ga_id
from goods_attribute a where a.ga_ca_id='178' and a.ga_value='red'
and exists(select b.ga_id
from goods_attribute b where a.ga_id=b.ga_id and b.ga_ca_id='207' and b.ga_value='a')
||
||
thh1
FROM goods_chs AS g
LEFT JOIN goods_attribute AS ga ON ( ga.ga_gid = g.g_id )
WHERE ga.ga_ca_id = '178'
AND ga.ga_value = 'red'
AND EXISTS (SELECT b.g_id, gab. *
FROM goods_chs AS b
LEFT JOIN goods_attribute AS gab ON ( gab.ga_gid = b.g_id )
WHERE g.g_id = b.g_id
AND gab.ga_ca_id = '207'
AND gab.ga_value = 'a'
)MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT b.g_id, gab. *