1. 程式人生 > >mysql 巢狀查詢

mysql 巢狀查詢

1.

SELECT
	typeName,
	NAME,
	money,
	down_Url,
	plug1.*
FROM
	plug1
WHERE
	NAME IN (
		SELECT
			NAME
		FROM
			(
				SELECT
					count(*) AS cishu,
					NAME,
					typeName
				FROM
					plug1
				GROUP BY
					NAME,
					typeName
			) t
		WHERE
			t.cishu > 1
	)
ORDER BY
	NAME,
	typeName

2 在1 基礎再套一層
 
SELECT
	*
FROM
	(
		SELECT
			typeName,
			NAME,
			money,
			down_Url
		FROM
			plug1
		WHERE
			NAME IN (
				SELECT
					NAME
				FROM
					(
						SELECT
							count(*) AS cishu,
							NAME,
							typeName
						FROM
							plug1
						GROUP BY
							NAME,
							typeName
					) t
				WHERE
					t.cishu > 1
			)
		ORDER BY
			NAME,
			typeName
	) t
WHERE
	t.money <> '試用'
OR t.money <> '免費'