我有MySQL查询:如何正确地在mysql中查询mysql?
SET @row = 0;
SELECT @row := @row + 1 AS Row, col1
FROM table1;
但如何正确地把里面$sql=",,,,,,";
?
我TRID:
SET @row = 0;
$sql = "SELECT @row := @row + 1 AS Row, col1
FROM table1";
但我认为它不工作,那么尝试:
$sql = "SELECT @row := @row + 1 AS Row, col1
FROM table1,
(SELECT @rownum = 0)";
没有错误,但我得到结果的行空 这真正的查询:
SELECT @rownum:[email protected]+1 AS No, B.Serial_number,A.Symptom
FROM oqc_defect A
JOIN (SELECT @rownum := 0) r
LEFT JOIN inspection_report B
ON A.Model = B.Model
WHERE Appearance = 'NG' OR Packing = 'NG' OR Accesories = 'NG' OR Tuner = 'NG' OR General_operation = 'NG'
GROUP BY A.Model
我得到的结果一样:
No Serial_number Symptom
1 106X0336 Remocon Wrong Part Number
6 106X0528 Trimplate have scratch
7 106V8024 IC breaket not lock to top chassis
8 106X5890 IC breaket not lock to top chassis
9 106X5866 IC breaket not lock to top chassis
10 106X0781 Finder crack at bottom side
不要在DB中计算rownum!这是应用程序的工作。 – binaryLV 2011-05-20 07:22:23