このようなSQL ServerにSQLクエリが1つあります
SELECT
CASE WHEN ROW_NUMBER() OVER(PARTITION BY _no ORDER BY _no asc) = 1 THEN
_no ELSE '' END
as row_no,
_no,
_name,
r._names
FROM
(
SELECT '1' as _no, 'vikas' as _name UNION ALL
SELECT '1', 'kratika' UNION ALL
SELECT '2', 'vikas' UNION ALL
SELECT '1', 'kratika kastwar'
) t
INNER JOIN
(
SELECT '1' as _nos, 'One' as _names UNION ALL
SELECT '2', 'two'
) r
ON r._nos = t._no
ORDER BY _no
出力:
row_no _no _name _names
------ ---- --------------- ------
1 1 kratika One
1 kratika kastwar One
1 vikas One
2 2 vikas two
そして、私はこのようにMySQLでやっているのと同じです
SELECT
CASE WHEN _no = @i THEN '' ELSE @i := _no END
as row_no,
_no,
_name,
r._names
FROM
(
SELECT '1' as _no, 'vikas' as _name UNION ALL
SELECT '1', 'kratika' UNION ALL
SELECT '2', 'vikas' UNION ALL
SELECT '1', 'kratika kastwar'
) t
INNER JOIN
(
SELECT '1' as _nos, 'One' as _names UNION ALL
SELECT '2', 'two'
) r
ON r._nos = t._no
,
(SELECT @i := '') temp
ORDER BY _no
出力:
1 1 vikas One
1 kratika One
1 1 kratika kastwar One
2 2 vikas two
しかし、私は このようなMySQLの出力を期待しています
1 1 kratika One
1 kratika kastwar One
1 vikas One
2 2 vikas two
MySQLでこのようなクエリを使用したくありません。desc here MYSQL Order By W/Count
SELECT
CASE WHEN _no = @i THEN '' ELSE @i := _no END
as row_no,
_no,
_name,
_names
FROM
(SELECT
*
FROM
(
SELECT '1' as _no, 'vikas' as _name UNION ALL
SELECT '1', 'kratika' UNION ALL
SELECT '2', 'vikas' UNION ALL
SELECT '1', 'kratika kastwar'
) t
INNER JOIN
(
SELECT '1' as _nos, 'One' as _names UNION ALL
SELECT '2', 'two'
) r
ON r._nos = t._no
,
(SELECT @i := '') temp
ORDER BY _no) t
MySQLで同じことを達成する方法、クエリのパフォーマンスは主要なパラメーターです